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

    JNDI unable to connect with HornetQ behind a load balancer

    johnnysoccer

      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: 10.24.84.142; 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?
      John
        • 1. Re: JNDI unable to connect with HornetQ behind a load balancer
          clebert.suconic

          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
            johansyd

            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:

             

            Configs:

             

            hornetq-beans.xml

             

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

                  <property name="namingInfo">

                     <inject bean="Naming"/>

                  </property>

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

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

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

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

               </bean>

             

             

            hornetq-configuration.xml

               <connectors>

                  <connector name="netty">

                     <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

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

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

                  </connector>

             

             

                  <connector name="netty-throughput">

                     <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

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

                  </connector>

               </connectors>

             

             

               <acceptors>

                  <acceptor name="netty">

                     <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

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

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

                  </acceptor>

             

             

                  <acceptor name="netty-throughput">

                     <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

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

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

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

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

                  </acceptor>

               </acceptors>

             

            hornetq-jms.xml

             

                    <queue name="CrawlerQueue">

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

                    </queue>

             

                    <queue name="ClassificationQueue">

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

                    </queue>

             

             

            Map connectionParams = new HashMap();

            connectionParams.put(TransportConstants.PORT_PROP_NAME,5445);

            connectionParams.put(TransportConstants.HOST_PROP_NAME,"your.public.host.name");

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

            connection.start();

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

            producer.send(message);

            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