1 Reply Latest reply on Mar 12, 2012 2:44 PM by odain

    no route to host using BrokerService

    odain

      I'm trying to set up a publisher using an embedded broker in a single process and a set of subscribers running in other processes connected via tcp. It all works if the subscribers are running on the same machine as the publisher and they connect using tcp://localhost:61616. However, if I try to run the subscribers on a different machine I get "no route to host" errors.

       

      The broker and publisher are set up as follows:

       

       

      broker = new BrokerService();

      // connection for the subscribers

      broker.addConnector("tcp://localhost:61616");

      broker.start();

       

      // Create a producer.

      String connectURL =

                      "vm://SPAR?marshal=false&create=false";

      ActiveMQConnectionFactory connectionFactory =

                      new ActiveMQConnectionFactory(connectURL);

      connection = connectionFactory.createTopicConnection();

      session = connection.createTopicSession(

                      false, Session.AUTO_ACKNOWLEDGE);

      Topic topic = session.createTopic(TOPIC_NAME);

      producer = session.createProducer(topic);

       

      I've tried both "tcp://localhost:61616" and "tcp://192.168.100.11:61616" in the initial addConnector call (192.168.100.11 is the IP of the machine running the broker). The client code is as follows:

       

              ActiveMQConnectionFactory connectionFactory =

                      new ActiveMQConnectionFactory(connectionUrl);

              connection = connectionFactory.createTopicConnection();

              connection.start();

              session = connection.createTopicSession(

                    false, Session.AUTO_ACKNOWLEDGE);

       

       

              Topic topic = session.createTopic(PublishingBroker.TOPIC_NAME);

              userSubscriber = session.createSubscriber(

                      topic, subscriptionRule, false);

              userSubscriber.setMessageListener(userMessageListener);

       

      here connectionUrl comes from the command line and, if running on the same machine as the broker, is set to tcp://localhost:61616 and if running on a different host it's tcp://192.168.100.11:61616 which is the address of the machine where the broker is running.

       

      As noted above if the subscriber and the broker are running on the same machine at connectionUrl = tcp://localhost:61616 and the broker is started with tcp://localhost:61616 everything works as expected. However, if I move the subscriber to a different machine I get a "no route to host" error:

       

      Exception in thread "main" javax.jms.JMSException: Could not connect to broker URL: tcp://192.168.100.11:61616. Reason: java.net.NoRouteToHostException: No route to host

              at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)

              at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:286)

              at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230)

              at org.apache.activemq.ActiveMQConnectionFactory.createTopicConnection(ActiveMQConnectionFactory.java:208)

              at edu.mit.ll.spar.SparClient.(SparClient.java:71)

              at edu.mit.ll.spar.TestNetworkClient.run(TestNetworkClient.java:95)

              at edu.mit.ll.spar.TestNetworkClient.main(TestNetworkClient.java:131)

      Caused by: java.net.NoRouteToHostException: No route to host

              at java.net.PlainSocketImpl.socketConnect(Native Method)

              at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)

              at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)

              at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)

              at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)

              at java.net.Socket.connect(Socket.java:546)

              at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:484)

              at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:447)

              at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53)

              at org.apache.activemq.transport.InactivityMonitor.start(InactivityMonitor.java:126)

              at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)

              at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)

              at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)

              at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)

              at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:266)

              ... 5 more

       

      I've tried this with the broker configured with broker.addConnector("tcp://localhost:61616"); and with broker.addConnector("tcp://192.168.100.11:61616");. One potentially complicating factor is that both machines are multi-homed (have more than one NIC card and more than 1 IP address). As a result I don't think the tcp://localhost connector can work as ActiveMQ wouldn't know which address it should bind to. When started with tcp://192.168.100.11:61616 netstat shows that the broker is indeed running and listening on that port:

       

      ]$ netstat -t -l

      Active Internet connections (only servers)

      Proto Recv-Q Send-Q Local Address               Foreign Address             State

      ... other stuff...

      tcp        0      0 ::ffff:192.168.100.11:61616 :                         LISTEN

       

       

      Also note that these machines are able to talk to each other on the network. They can ping each other and I can ssh from one to the other and vice versa.

       

      Any idea what I'm doing wrong??