2 Replies Latest reply on Jul 27, 2011 10:36 AM by Johan Sydseter

    JNDI unable to connect with HornetQ behind a load balancer

    John Muhlestein Newbie

      While trying to create a connection to HornetQ from a client where the HornetQ server is behind a load balancer, jndi is not able to communicate in order to set up the client. HornetQ is running in standalone mode.


      In the hornetq-beans.xml we have set up the bindAddress and rmiBindAddress for the JndiServer to be the real ip address of the machine.  The client side needs to be using the ip address defined in the load balancer for the machine.


      The underlying error follows (the host ip address is the real address of the machine, and the client has no knowledge of that machine, or access to it because the address on the load balancer for that machine is different):


      Caused by: java.rmi.ConnectException: Connection refused to host:; nested exception is:

      java.net.ConnectException: Connection timed out

      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601) [na:1.6.0_14]

      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) [na:1.6.0_14]

      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184) [na:1.6.0_14]

      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110) [na:1.6.0_14]

      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) [jnp-client.jar:na]

      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726) [jnp-client.jar:na]

      When we have done this kind of thing with JBoss in the past, we were able to set the jndi bind address to "localhost", and then have a little host name magic take place.  We can't use "localhost" for machines connecting that are not local according to the documentation.  Any ideas on how to get past this?
        • 1. Re: JNDI unable to connect with HornetQ behind a load balancer
          Clebert Suconic Master

          I'm not really sure what this load balancer is doing.


          The client needs access to the machine anyway. If you're putting a proxy or firewal in front of it for some reason, you need to proxy it properly.



          Anyway, you're not required to use JNDI in order to establish the clients with HornetQ. You can use direct instantiation of the Factories with HornetQ (Look at the documentation and examples for more information).

          • 2. Re: JNDI unable to connect with HornetQ behind a load balancer
            Johan Sydseter Newbie

            I have had the same Problem for a couple of days now. And finally gave up on making lookups with jndi. I went through all the logs I could find and couldn't find a single log entry showing that a connection was established. Still I localy got "Coonection refused" together with the ip-address of one of the backend-servers which proves that the connection is being forwarded by the load balancer.


            A professor I spoke with said it could be due to the fact that the load balancer was trying to send a a ip6 address to the backend servers which where expecting a ip4 address or something in this direction.


            You should be able to get around your problem by connecting directly to the connector. I just managed to this. My solution is this:






               <bean name="JNDIServer" class="org.jnp.server.Main">

                  <property name="namingInfo">

                     <inject bean="Naming"/>


                  <property name="port">${jnp.port:8050}</property>

                  <property name="bindAddress">${jnp.host:}</property>

                  <property name="rmiPort">${jnp.rmiPort:8049}</property>

                  <property name="rmiBindAddress">${jnp.host:}</property>






                  <connector name="netty">


                     <param key="host"  value="${hornetq.remoting.netty.host10.6.0.55}"/>

                     <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>




                  <connector name="netty-throughput">


                     <param key="host"  value="${hornetq.remoting.netty.host10.6.0.55}"/>

                     <param key="port"  value="${hornetq.remoting.netty.batch.port:1098}"/>

                     <param key="batch-delay" value="50"/>






                  <acceptor name="netty">


                     <param key="host"  value="${hornetq.remoting.netty.host:}"/>

                     <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>




                  <acceptor name="netty-throughput">


                     <param key="host"  value="${hornetq.remoting.netty.host:}"/>

                     <param key="port"  value="${hornetq.remoting.netty.batch.port:1098}"/>

                     <param key="batch-delay" value="50"/>

                     <param key="direct-deliver" value="false"/>






                    <queue name="CrawlerQueue">

                            <entry name="/queue/CrawlerQueue" />



                    <queue name="ClassificationQueue">

                            <entry name="/queue/ClassificationQueue"/>




            Map connectionParams = new HashMap();



            TransportConfiguration transportConfiguration = new TransportConfiguration(

                 "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", connectionParams);

            ConnectionFactory cf = new HornetQConnectionFactory(transportConfiguration);

            Queue crawlerQueue = new HornetQQueue("CrawlerQueue");


            Connection connection = cf.createConnection();

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);


            MessageProducer producer = session.createProducer(crawlerQueue);

            MessageConsumer consumer = session.createConsumer(crawlerQueue);


            TextMessage message = session.createTextMessage("This is an order");


            TextMessage receivedMessage = (TextMessage) consumer.receive();

            System.out.println("Got order: " + receivedMessage.getText());


            // output: Got order: This is an order


            -Make sure that the hornetQ version on the server and on your client is the same. //2.1.2 doesn't like 2.2.2

            -Also make sure that all the ports you are using is open on the public host