2016-03-30 25 views
2

Şu anda, proxy sunucusu üzerinden Internet'e ActiveMQ iletisini göndermede sorun yaşıyorum.Proxy üzerinden ActiveMQ üzerinden nasıl ileti gönderilir

Benim ağ mimarisi:

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

Ben activemq belgelerine arandığını ama çok, ActiveMQ API hiçbir şey bulunamadı.

Kodu:

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); 
} 

Hata:

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 

cevap

1

sorunu proxy üzerinden gönderirken de LAN üzerinde http://activemq.apache.org/tcp-transport-reference.html

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

Kodum çalışır, ancak, bu hatayı yükseltmek Muhtemelen proxy'nin kendisinde olacak. Proxy'niz protokolünüze ve/veya hedefinize izin vermiyorsa, tüm isteklerinizi engeller.

Proxy'ler genellikle bu tür isteklere izin verdiğinden, TCP yerine HTTP (veya HTTPS) protokolünü kullanmayı deneyin.

<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> 

bir göz atın:

Yani, komisyoncu bir HTTP taşıma konektörü ekleyebilir ve istemciden HTTP kullanarak tekrar deneyin Öte yandan HTTP and HTTPS transports

, ayrıca deneyebilirsiniz Mesajları yayınlamak/tüketmek için REST API.

+0

Teşekkürler kardeşim, deneyeceğim. –

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(); 
    } 

} 
İlgili konular