11 Replies Latest reply on Aug 27, 2014 10:04 PM by jbertram

    jndi lookup from jboss eap to remote hornetq server failed

    kts92tln8

      added following queue in hornetq config (from hornetq-jms.xml)

       

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

      jboss config (from standalone-full.xml)

       

      <subsystem xmlns="urn:jboss:domain:messaging:1.4">
          <hornetq-server>
              <persistence-enabled>true</persistence-enabled>
              <journal-type>NIO</journal-type>
              <journal-min-files>2</journal-min-files>
      
              <connectors>
                  <netty-connector name="netty" socket-binding="messaging"/>
                  <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                      <param key="batch-delay" value="50"/>
                  </netty-connector>
                  <netty-connector name="netty-remote" socket-binding="messaging">
                      <param key="host" value="localhost"/>
                      <param key="port" value="5445"/>
                  </netty-connector>
                  <in-vm-connector name="in-vm" server-id="0"/>
              </connectors>
      
              <security-settings>
                  <security-setting match="#">
                      <permission type="send" roles="guest"/>
                      <permission type="consume" roles="guest"/>
                      <permission type="createNonDurableQueue" roles="guest"/>
                      <permission type="deleteNonDurableQueue" roles="guest"/>
                  </security-setting>
              </security-settings>
      
              <address-settings>
                  <address-setting match="#">
                      <dead-letter-address>jms.queue.DLQ</dead-letter-address>
                      <expiry-address>jms.queue.ExpiryQueue</expiry-address>
                      <redelivery-delay>0</redelivery-delay>
                      <max-size-bytes>10485760</max-size-bytes>
                      <page-size-bytes>2097152</page-size-bytes>
                      <address-full-policy>PAGE</address-full-policy>
                      <message-counter-history-day-limit>10</message-counter-history-day-limit>
                  </address-setting>
              </address-settings>
      
              <jms-connection-factories>
                  <connection-factory name="InVmConnectionFactory">
                      <connectors>
                          <connector-ref connector-name="in-vm"/>
                      </connectors>
                      <entries>
                          <entry name="java:/ConnectionFactory"/>
                      </entries>
                  </connection-factory>
                  <connection-factory name="RemoteConnectionFactory">
                      <connectors>
                          <connector-ref connector-name="netty"/>
                      </connectors>
                      <entries>
                          <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                      </entries>
                  </connection-factory>
                  <pooled-connection-factory name="hornetq-ra">
                      <transaction mode="xa"/>
                      <connectors>
                          <connector-ref connector-name="netty-remote"/>
                      </connectors>
                      <entries>
                          <entry name="java:/JmsXA"/>
                      </entries>
                      <ha>true</ha>
                      <client-failure-check-period>10</client-failure-check-period>
                      <retry-interval>1000</retry-interval>
                      <retry-interval-multiplier>1.0</retry-interval-multiplier>
                      <max-retry-interval>60000</max-retry-interval>
                      <reconnect-attempts>1000</reconnect-attempts>
                  </pooled-connection-factory>
              </jms-connection-factories>
          </hornetq-server>
      </subsystem>
      
      

       

      ejb deployed in the jboss server tries to put a msg on the queue using following code--

       

      ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:/JmsXA");
      dest = (Destination) ctx.lookup("/queue/OrderQueue");
      con = cf.createConnection();
      session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
      producer = session.createProducer(dest);
      tmsg = session.createTextMessage(msg);
      producer.send(tmsg);
      
      

       

      got following exception

       

      Exception in thread "main" javax.naming.NameNotFoundException: queue/OrderQueue -- service jboss.naming.context.java.queue.OrderQueue
              at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
              at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:120)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
              at javax.naming.InitialContext.lookup(InitialContext.java:411)
              at sg.test.ejb.EchoBean.putMsg(EchoBean.java:88)
              at sg.test.ejb.EchoBean.putMsg(EchoBean.java:68)
              at sg.test.ejb.EchoBean.run(EchoBean.java:18)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
              ... more
      
      

       

      hornetq.log is attached

       

      Thanks for your help

        • 1. Re: jndi lookup from jboss eap to remote hornetq server failed
          jmesnil

          try using java:/queue/OrderQueue to define the entry in hornetq-jms.xml and the call to context.lookup().

           


          • 2. Re: jndi lookup from jboss eap to remote hornetq server failed
            jbertram

            What you're seeing is the expected behavior.  You've defined a queue on the remote HornetQ server, but you're trying to look it up locally (where it doesn't exist).

            • 3. Re: jndi lookup from jboss eap to remote hornetq server failed
              jmesnil

              Justin is right.

               

              I misunderstood your question and thought that you had deployed the OrderQueue on WildFly by deploying a hornetq-jms.xml file with your app.

              • 4. Re: jndi lookup from jboss eap to remote hornetq server failed
                kts92tln8

                does that mean while creating intialcontext on jboss side I need to specify

                 

                    java.naming.provider.url=jnp://localhost:1099

                    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

                    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

                 

                as jndi server is running on localhost:1099

                 

                    <!-- The Stand alone server that controls the jndi server-->

                    <bean name="StandaloneServer" class="org.hornetq.jms.server.impl.StandaloneNamingServer">

                      <constructor>

                         <parameter>

                            <inject bean="HornetQServer"/>

                         </parameter>

                      </constructor>

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

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

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

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

                    </bean>

                 

                or I can't connect using localhost and I need specify ipaddress (specific or 0.0.0.0) for jnp.host and use that in the java.naming.provider.url while creating context.

                 

                also, what is rmiPort/BindAddress is for, I found not documentation, StandaloneNamingServer (HornetQ JMS Server 2.4.0.Final API)

                 

                Thanks

                • 5. Re: jndi lookup from jboss eap to remote hornetq server failed
                  jbertram

                  does that mean while creating intialcontext on jboss side I need to specify

                   

                      java.naming.provider.url=jnp://localhost:1099

                      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

                      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

                   

                  as jndi server is running on localhost:1099

                  You can certainly point your InitialContext at the remote HornetQ server.  Just make sure you still look up the connection factory locally.  That said, it isn't strictly necessary to look-up the destination from JNDI on the server that's actually hosting it as the destination stub doesn't contain anything special linking it to the server from which it was looked up.  You have 3 alternatives that I can see to a remote JNDI look-up:

                  • Define the JMS queue locally on your EAP server and look that up.
                  • Use javax.jms.Session.createQueue(String) to programmatically instantiate the destination.  In this case I believe you would use "OrderQueue".
                  • Use org.hornetq.api.jms.HornetQJMSClient.createQueue(String) to programmatically instantiate the destination.  In this case I believe you would use "jms.queue.OrderQueue".

                   

                  or I can't connect using localhost and I need specify ipaddress (specific or 0.0.0.0) for jnp.host and use that in the java.naming.provider.url while creating context.

                  If both applications (i.e. Wildfly and HornetQ) are running on the same physical or virtual machine then you can specify "localhost" for "java.naming.provider.url".  However, this will break if you move the applications to different machines.  I wouldn't use "0.0.0.0".

                   

                  also, what is rmiPort/BindAddress is for, I found not documentation, StandaloneNamingServer (HornetQ JMS Server 2.4.0.Final API)

                  • Port: The jnp protocol listening port for the NamingService. If not specified default is 1099, the same as the RMI registry default port.
                  • RmiPort: The RMI port on which the RMI Naming implementation will be exported. If not specified the default is 0 which means use any available port.
                  • BindAddress: The specific address the NamingService listens on. This can be used on a multi-homed host for a java.net.ServerSocket that will only accept connect requests on one of its addresses.
                  • RmiBindAddress: The specific address the RMI server portion of the NamingService listens on. This can be used on a multi-homed host for a java.net.ServerSocket that will only accept connect requests on one of its addresses. If this is not specified and the BindAddress is, the RmiBindAddress defaults to the BindAddress value.
                  • 6. Re: jndi lookup from jboss eap to remote hornetq server failed
                    kts92tln8

                    Thanks for reply.

                     

                    We are using jca connector (java:/JmsXA) to connect to remote hornetq and we dont want to (and should not as per doc) directly connect to

                    hornetq server by proving url and jnp port.

                     

                    if we use option 1, "Define the JMS queue locally on your EAP server and look that up." then we wont be using jndi server running in hornerq server ?

                    if we use option 2, "Use javax.jms.Session.createQueue(String)", then we wont be using jndi lookup for the queue at all ?

                    if we use option 3, "Use org.hornetq.api.jms.HornetQJMSClient.createQueue(String)", then again we wont be using jndi lookup for the queue ?

                     

                    so jboss(wildfly) cant do use jndi services running in the hornetq remote server (jnp) to do the jndi lookup for the queue ? at this point we dont see point of running jndi services in hornetq as we dont have any other client then jboss requires jndi lookup, for standalone client we can use coreapi.

                     

                    and the reason we should use "OrderQueue" for option 2 is its value of the queue name attribute, it has nothing to do with entry name ?

                      

                         <queue name="OrderQueue">

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

                         </queue>

                     

                    with option 2, since we are using jca we still get all jee good stuff, connection/session/consumer/producer pooling and transactions.

                    • 7. Re: jndi lookup from jboss eap to remote hornetq server failed
                      jbertram

                      We are using jca connector (java:/JmsXA) to connect to remote hornetq and we dont want to (and should not as per doc) directly connect to

                      hornetq server by proving url and jnp port.

                      I know you are using the JCA based connection factory.  I've been trying to explain your options to you for this specific use-case.  I enumerated 3 options that avoid a remote JNDI lookup for your application running in the application server.

                       

                      if we use option 1, "Define the JMS queue locally on your EAP server and look that up." then we wont be using jndi server running in hornerq server ?

                      You won't be using JNDI from your application running in the application server.  However, you still might need JNDI for traditional, standalone JMS clients.

                       

                      if we use option 2, "Use javax.jms.Session.createQueue(String)", then we wont be using jndi lookup for the queue at all ?

                      That's correct.

                       

                      if we use option 3, "Use org.hornetq.api.jms.HornetQJMSClient.createQueue(String)", then again we wont be using jndi lookup for the queue ?

                      That's correct.

                       

                      so jboss(wildfly) cant do use jndi services running in the hornetq remote server (jnp) to do the jndi lookup for the queue ?

                      I'm not sure I understand your question, but here's my best shot at what I think is a relevant answer...

                       

                      I'm not aware of any container-managed component that would allow an application running in the container to perform a local JNDI look-up and have that somehow bridged to the remote HornetQ server.

                       

                      at this point we dont see point of running jndi services in hornetq as we dont have any other client then jboss requires jndi lookup, for standalone client we can use coreapi.

                      Ok.

                       

                      and the reason we should use "OrderQueue" for option 2 is its value of the queue name attribute, it has nothing to do with entry name ?

                      That's correct.  The "entry" is related to JNDI which you wouldn't be using.

                       

                      with option 2, since we are using jca we still get all jee good stuff, connection/session/consumer/producer pooling and transactions.

                      To be clear, it doesn't matter how you get a reference to the destination (e.g. by JNDI look-up or direct instantiation) as it relates to JCA.  You will still get connection pooling and automatic resource enlistment in your JTA transactions with any of the 4 methods we've discussed.

                      1 of 1 people found this helpful
                      • 8. Re: jndi lookup from jboss eap to remote hornetq server failed
                        kts92tln8

                        thanks for reply, would it be possible to run a mdb using queue name similar to used in producer code,

                           javax.jms.Session.createQueue(String)

                        or MDB will require to define the JMS queue locally on EAP server and use that.

                        • 9. Re: jndi lookup from jboss eap to remote hornetq server failed
                          jbertram

                          The HornetQ JCA Resource Adapter code used for message inflow (i.e. the code used when initializing an MDB) already takes care of this.  Just set the "useJNDI" activation configuration property to "false" and use the HornetQ name for the "destination" activation configuration property.

                          • 10. Re: jndi lookup from jboss eap to remote hornetq server failed
                            kts92tln8

                            great, thanks again. It would be helpful if you could point out source files as well (HornetQ JCA Resource Adapter code used for message inflow), also is there a reference of properties that can go in ActivationConfigProperty (javadoc/source/document), for MDB at least.

                             

                            To specify the host/port MDB should connect to, in another thread (https://community.jboss.org/thread/195968) you suggested using @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=remoteHost;port=5445"), however how does it work in clustered env. If we run HornetQ cluster where there are multiple instances of the queue on each server, do we need to run one MDB (in jboss EAP) for each HornetQ server queue or we could specify multiple hosts in connectionParameters and some sort of load balancing (roundrobin) policy will be applied when consuming messages.

                             

                            on consuming side, I understand we can specify multiple connectors (one for each host in the cluster), and some client side loadbal policy will be applied when msgs are produced.

                             

                              <pooled-connection-factory name="hornetq-ra">

                                  <transaction mode="xa"/>

                                  <connectors>

                                      <connector-ref connector-name="netty-remote-host1"/>

                                      <connector-ref connector-name="netty-remote-host2"/>

                                      <connector-ref connector-name="netty-remote-host3"/>

                                  </connectors>

                            • 11. Re: jndi lookup from jboss eap to remote hornetq server failed
                              jbertram

                              It would be helpful if you could point out source files as well (HornetQ JCA Resource Adapter code used for message inflow)...

                              As the documentation indicates, the source is on GitHub.  The code is organized into numerous sub-modules.  The code you're looking for is in the "hornetq-ra" module.  Look for org.hornetq.ra.inflow.HornetQActivation#setupDestination.

                               

                              ...also is there a reference of properties that can go in ActivationConfigProperty (javadoc/source/document), for MDB at least.

                              The documentation has this.

                               

                              ...how does it work in clustered env. If we run HornetQ cluster where there are multiple instances of the queue on each server, do we need to run one MDB (in jboss EAP) for each HornetQ server queue or we could specify multiple hosts in connectionParameters and some sort of load balancing (roundrobin) policy will be applied when consuming messages.

                              You can specify multiple host;port combinations separating each with a comma.  These define the initial connectors for the MDB connection just like a list of connectors on a connection factory does. 

                               

                              To be clear, an MDB only has 1 connection to any server at any given point.  That said, even one client connected to one server in a cluster will be able to consume all the applicable messages in the cluster if redistribution is configured as necessary.  See the documentation for more on this.