4 Replies Latest reply on Jul 31, 2014 2:00 AM by Toan Dao

    HornetQ: Remote client connect to HornetQ server which was running in VM

    Toan Dao Newbie

      I'm new in HornetQ, and I have tried to figure out for 2-3 days but hopeless.
      Expected: 1 HornetQ stand-alone and sender (in VM)

                      2 clients as receivers (in real machine)

       

      Sender:

      Map<String, Object> connectionParams = new HashMap<String, Object>();

      connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");

      connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);

      TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);

      ConnectionFactory cf = new HornetQTopicConnectionFactory(false, transportConfiguration);

      connection = cf.createConnection();

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

      connection.start();

      topic = HornetQJMSClient.createTopic("myTopic");

      MessageProducer producer = session.createProducer(topic);

       

      Receiver:

      Properties p = new Properties();

               p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

               p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");

               p.put(Context.PROVIDER_URL, "remote://localhost:5445");

               p.put(Context.SECURITY_PRINCIPAL, "admin");

               p.put(Context.SECURITY_CREDENTIALS, "admin");

               InitialContext context  = new InitialContext(p);

      ConnectionFactory factory = (ConnectionFactory)context.lookup("/ConnectFactory");

      connection = (Connection) factory.createConnection();

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

      topic = (HornetQTopic) HornetQJMSClient.createTopic("myTopic");

      MessageConsumer consumer = session.createConsumer(topic);

       

       

      When I ./run.sh in VM (sender work fine)

                then I run clients(receivers) in real machine but it cannot connect to HornetQ server (which is running in VM)

       

      javax.naming.NamingException: Failed to connect to any server. Servers tried: [remote://localhost:5445]

        at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:213)

        at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:144)

        at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:125)

        at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:241)

        at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)

        at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)

        at javax.naming.InitialContext.lookup(InitialContext.java:411)

        at com.dtv.apg.hornetq.SubA.run(SubA.java:70)

        at java.lang.Thread.run(Thread.java:722)

       

      Thank you for any suggestion.

        • 1. Re: HornetQ: Remote client connect to HornetQ server which was running in VM
          Andy Taylor Master

          you are connecting to the wrong port for JNDI, JNDI runs on 1099 by default. port 5445 is the default port for the HornetQ connectors.

          1 of 1 people found this helpful
          • 2. Re: HornetQ: Remote client connect to HornetQ server which was running in VM
            Toan Dao Newbie

            I have tried

                     Properties p = new Properties();

                     p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

                     p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");

                     p.put(Context.PROVIDER_URL, "jnp://localhost:1099");

                     p.put(Context.SECURITY_PRINCIPAL, "admin");

                     p.put(Context.SECURITY_CREDENTIALS, "admin");

                     InitialContext context  = new InitialContext(p);

            But it shows the same.

             

            Let's me make it short:

            1. I start HornetQ (stand-alone) in VM including hornetq-configuration.xml & hornetq-jms.xml etc.

            2. I run my SenderProject in VM also, then send some messages.

            3. I try to run ReceiverProject in real machine to receive some messages. (but it won't work, it can't connect to HornetQ (stand-alone server)

             

            FYI:

            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.host:localhost}"/>

                     <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.host:localhost}"/>

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

                     <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:localhost}"/>

                     <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:localhost}"/>

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

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

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

                  </acceptor>

               </acceptors>

            • 3. Re: HornetQ: Remote client connect to HornetQ server which was running in VM
              Andy Taylor Master

              are you running InVM (embedded) or standalone (run.sh)? if the former and you want to use JNDI then you would have to embed a naming server as well.

              • 4. Re: HornetQ: Remote client connect to HornetQ server which was running in VM
                Toan Dao Newbie

                Now I try to keep as simple as possible


                1. I start HornetQ in other PC (10.88.106.223)

                <connectors>

                      <connector name="netty">

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

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

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

                      </connector>

                </connectors>

                <acceptors>

                      <acceptor name="netty">

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

                         <param key="host"  value="10.88.106.223"/>

                         <param key="port"  value="5445"/>

                      </acceptor>

                </acceptors>


                2. Then I run a simple java app ReceiverProject (as Consumer) in other PC (10.88.106.195)
                My Consumer:

                     Map<String, Object> connectionParams = new HashMap<String, Object>();

                         connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);

                         connectionParams.put(TransportConstants.HOST_PROP_NAME, "10.88.106.223");

                         TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(),           connectionParams);

                         TopicConnectionFactory cf = new HornetQTopicConnectionFactory(false, transportConfiguration);


                And it's work, it seems like I have picked the wrong IP for Virtual Machine (127.0.0.1). Thanks for your quick response.

                And have a nice day.