7 Replies Latest reply on May 2, 2014 1:52 PM by Justin Bertram

    How to connect to a remote queue using MDB

    Johan van Kampen Newbie

      I am trying to connect to a queue on a remote server. In my setup I have a 'producer' server holding the queue (queue/test) and a 'consumer' server running a ear-file containing the MDB

       

      I couldn't find any examples on how to do this via http-remoting (don't know if it is possible?). Therefore I tried it using a netty-connector.

      Until now without complete success. The steps I took are :

      1. configuring WildFly to use netty - connector. As far as I can see it works. See below output of startup-log

      12:13:45,075 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 58) HQ221020: Started Netty Acceptor version unknown 127.0.0.1:5445

      12:13:45,081 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 58) HQ221020: Started Netty Acceptor version unknown 127.0.0.1:5455

      12:13:45,082 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 58) HQ221007: Server is now live

       

      2. add queues to 'producer' server

      12:13:45,082 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 58) HQ221001: HornetQ Server version 2.4.1.Final (Fast Hornet, 124) [17f3235f-cfb4-11e3-a34f-894a05f9ecb4]

      12:13:45,098 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 58) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory

      12:13:45,099 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 59) HQ221003: trying to deploy queue jms.queue.testQueue

      12:13:45,105 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 59) JBAS011601: Bound messaging object to jndi name queue/test

      12:13:45,105 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 59) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/test

      12:13:45,106 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221003: trying to deploy queue jms.queue.tutorialQueue

      12:13:45,108 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 60) JBAS011601: Bound messaging object to jndi name java:jboss/exported/tutorialQueue

      12:13:45,109 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 61) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory

      12:13:45,141 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-8) JBAS010406: Registered connection factory java:/JmsXA

       

      3. Deploy MDB configured like :

      @MessageDriven(

              name = "TutorialConsumer",

              activationConfig = {

                      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test"),

                      @ActivationConfigProperty(propertyName = "user", propertyValue = "quickstartUser"),

                      @ActivationConfigProperty(propertyName = "password", propertyValue = "quickstartPwd1!"),

                      @ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "-1"),

                      @ActivationConfigProperty(propertyName = "setupAttempts", propertyValue = "-1"),

                      @ActivationConfigProperty(propertyName="connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),

                      @ActivationConfigProperty(propertyName="connectionParameters", propertyValue = "host=localhost;port=5455")

              })

       

      4. I see the deployment 'succeeding'. However the connection with the queue on the 'producer' server not :

      12:17:34,076 INFO  [org.hornetq.ra] (default-threads - 16) HQ151000: awaiting topic/queue creation queue/test

      12:17:36,077 INFO  [org.hornetq.ra] (default-threads - 16) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@5bb3a811 destination=queue/test destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=quickstartUser password=**** maxSession=15)

       

      Furthermore :

      * I also tried connecting to the server via port 5445 -> same result

      * changing the password results in a authentication failure on the producer. So, the MDB is trying to connect.

      * Messages aren't read from the queue

      * No errors are shown

       

      What am I missing ?

        • 1. Re: How to connect to a remote queue using MDB
          Justin Bertram Master

          If you to use the JNDI name for the destination then you'll need to properly configure the "jndiParams" activation configuration property on the MDB.  Here is the blurb from the non-yet-published documentation on this:

          A semicolon (';') delimited string of name=value pairs which represent the properties to be used for the destination JNDI look up. The properties depends on the JNDI implementation of the server hosting HornetQ. Typically only be used when the MDB is configured to consume from a remote destination and needs to look up a JNDI reference rather than the HornetQ name of the destination. Only relevant when "useJNDI" is true (default is an empty string).

           

          BTW, "useJNDI" defaults to true.

           

          The reason you have to define basically the same connection details in two different ways is because the JNDI lookup and the HornetQ connection are 100% independent of each other.  The underlying JNDI implementation might be completely different between 2 environments that have the same HornetQ version.

           

          However, you avoid this by simply using the HornetQ name of the destination rather than the JNDI name.

           

          Hope that helps.

          • 2. Re: How to connect to a remote queue using MDB
            Johan van Kampen Newbie

            To be honest I don't know what to put there. I did @ActivationConfigProperty(propertyName = "jndiParams", propertyValue = "destination=java:jboss/exported/jms/queue/test;destinationType=javax.jms.Queue") but that doesn't work.

            • 3. Re: How to connect to a remote queue using MDB
              Justin Bertram Master

              The "jndiParams" activation configuration property holds, "the properties to be used for the destination JNDI look up."  These are the same properties you would provide to the IntialContext when you're doing a normal JNDI lookup on a remote host.  You just stuff them into a single semi-colon delimited string of name=value pairs.

              1 of 1 people found this helpful
              • 4. Re: How to connect to a remote queue using MDB
                Johan van Kampen Newbie

                Almost there (I think)

                 

                I used configuration :

                @MessageDriven(

                        name = "TutorialConsumer",

                        activationConfig = {

                                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                                @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test"),

                                @ActivationConfigProperty(propertyName = "jndiParams", propertyValue = "java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory;java.naming.provider.url=http-remoting://127.0.0.1:8080;java.naming.security.principal=quickstartUser;java.naming.security.credentials=quickstartPwd1!")

                        })

                 

                Now I get a ClassNotFoundException "java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory"

                 

                I have in my maven pom :

                      <dependency>

                          <groupId>org.jboss.as</groupId>

                          <artifactId>jboss-as-client</artifactId>

                          <version>8.0.0.Final</version>

                      </dependency>

                 

                Based on the error I added the jboss-as-client-8.0.0.Final.jar as module:

                <?xml version="1.0" ?>

                <module xmlns="urn:jboss:module:1.1" name="org.jboss.as.client">

                    <resources>

                        <resource-root path="jboss-as-client-8.0.0.Final.jar"/>

                    </resources>

                </module>

                 

                No result : still the classnotfound exception.

                 

                Any idea?

                 

                BTW : the used settings function in a java-main class.

                • 5. Re: How to connect to a remote queue using MDB
                  Justin Bertram Master

                  Couple of things...

                  1. You don't need to add a new module since the class you need is already in the "org.jboss.remote-naming" module.  In any event, you must add a dependency to your application on the proper module or none of those classes will be loaded for you.
                  2. Why not save yourself this trouble and simply use the HornetQ name of the destination and set the "useJNDI" activation configuration property to "false"?
                  • 6. Re: How to connect to a remote queue using MDB
                    Johan van Kampen Newbie

                    I got it working (at last ) using your second suggestion.

                     

                    I think I am going to write a blog about it. Caused me a lot of headache. Thanks for your support.

                    • 7. Re: How to connect to a remote queue using MDB
                      Justin Bertram Master

                      HornetQ already ships examples of this.  For example, see this MDB which uses a customized pooled-connection-factory (i.e. "hornetq-ra-remote.rar") defined here.  This particular kind of configuration may be preferable to yours since much of the configuration is external from the MDB which makes it easier to manage.  This example is referenced in the HornetQ documentation here (see section 11.3.3.).

                      1 of 1 people found this helpful