2016-03-30 16 views
2

Derzeit habe ich Probleme mit dem Senden von ActiveMQ Nachricht an das Internet über Proxy-Server.So senden Sie eine Nachricht von ActiveMQ über Proxy

Meine Netzwerkarchitektur:

JMS Sender ---- |Proxy| --- JMS server (xx.xx.xx.xx) [on Internet] 

ich auf ActiveMQ in der Dokumentation gesucht, aber nichts gefunden, ActiveMQ zu API. http://activemq.apache.org/tcp-transport-reference.html

Is it possible to send JMS message over proxy? Any solution for this problem?

Mein Code Arbeit gut auf LAN, aber wenn über Proxy senden, heben sie Fehler:

Code:

public void createConnection() throws JMSException { 
    String jmsURL = "tcp://xx.xx.xx.xx:61616"; 
    TopicConnectionFactory factory 
      = (TopicConnectionFactory) new ActiveMQConnectionFactory(jmsURL); 
    TopicConnection connection = factory.createTopicConnection(); //Error here 
    TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 
    Topic topic = session.createTopic(topicName); 
    TopicPublisher publisher = session.createPublisher(topic); 
    publisher.setPriority(PRIORITY); 
    publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
} 

Fehler:

Exception in thread "main" javax.jms.JMSException: 
Could not connect to broker URL: tcp://xx.xx.xx.xx:61616. Reason: java.net.ConnectException: Connection timed out: connect 
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) 
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:360) 
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:305) 
    at org.apache.activemq.ActiveMQConnectionFactory.createTopicConnection(ActiveMQConnectionFactory.java:279) 
    at JMSSender.createConnection(JMSSender.java:55) 
    at MainClass.main(MainClass.java:142) 
Caused by: java.net.ConnectException: Connection timed out: connect 

Antwort

1

Das Problem wird wahrscheinlich auf dem Proxy selbst sein. Wenn Ihr Proxy Ihr Protokoll und/oder Ihr Ziel nicht erlaubt, blockiert es alle Ihre Anfragen.

Versuchen Sie, HTTP (oder HTTPS) anstelle von TCP zu verwenden, da Proxys diese Art von Anforderungen normalerweise zulassen.

Also, einen HTTP-Transport-Anschluss an Ihren Broker hinzufügen und versuchen Sie es erneut HTTP von Ihrem Client verwenden:

<transportConnectors> 
    <transportConnector name="tcp" uri="tcp://xx.xx.xx.xx:61616?trace=true"/> 
    <transportConnector name="http" uri="http://xx.xx.xx.xx:8080?trace=true" /> 
</transportConnectors> 

Werfen Sie einen Blick auf: HTTP and HTTPS transports

Auf der anderen Seite können Sie auch die versuchen, REST API Nachrichten zu veröffentlichen/konsumieren.

+0

Dank bro, ich werde es versuchen. –

1
**Use this code , it will work** 

import javax.jms.Connection; 
import javax.jms.ConnectionFactory; 
import javax.jms.Destination; 
import javax.jms.JMSException; 
import javax.jms.MessageProducer; 
import javax.jms.Session; 
import javax.jms.TextMessage; 

import org.apache.activemq.ActiveMQConnectionFactory; 

public class Sender { 

    private ConnectionFactory factory = null; 
    private Connection connection = null; 
    private Session session = null; 
    private Destination destination = null; 
    private MessageProducer producer = null; 

    public Sender() { 

    } 

    public void sendMessage() { 

     try { 
//   factory = new ActiveMQConnectionFactory(
//     ActiveMQConnection.DEFAULT_BROKER_URL); 

      factory = new ActiveMQConnectionFactory(
        "admin", 
        "admin", "nio://10.10.10.10:61616"); 
      connection = factory.createConnection(); 
      connection.start(); 
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      destination = session.createQueue("sample.queue"); 
      producer = session.createProducer(destination); 
      TextMessage message = session.createTextMessage(); 
      message.setText("Hello ...This is a sample message.. "+i); 
      producer.send(message); 
      System.out.println("Sent: " + message.getText()); 
      connection.stop(); 
      session.close(); 
      connection.close(); 

     } catch (JMSException e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     Sender sender = new Sender(); 
     sender.sendMessage(); 
    } 

} 
Verwandte Themen