7 Replies Latest reply on Feb 9, 2016 11:25 AM by jbertram

    How to configure an MDB to read a queue on a remote Wildfly server.

    kevinprendergast

      My problem : I have a Queue defined in my 'QueueHost' machine's standalone-full as ...

       

      <jms-queue name="testQueue">

           <entry name="jms/queue/test"/>

           <entry name="java:jboss/exported/jms/queue/test"/>

      </jms-queue>

       

      I can successfully connect to this queue from a .war inside the same QueueHost machine with a simple MDB.

       

      @MessageDriven(activationConfig = {

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

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

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

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

      }, mappedName = "TestQueue")

      public class TestMdb implements MessageListener {

       

        private static final Logger log = LoggerFactory.getLogger(TestMdb.class);

       

        public void onMessage(Message message) {

       

        if (message instanceof TextMessage) {

             TextMessage tm = (TextMessage) message;

        try {

             log.info("Text Message : " + tm.getText());

        } catch (JMSException e) {

             log.error(e.getLocalizedMessage());

        }

        }

        }

      }

       

      I can successfully produce messages to the testQueue from a simple Java client, connecting to http-remoting://localhost:80

      And these are happily consumed from the MDB. Awesome.

       

      But then I attempt to move the .war to a second, remote Wildfly Server and I can not establish the remote connection.

      Server 1 (QueueHost) : http is port 80.

      Server 2 (QueueClient) : port binding is offset by +100, because it's actually in the same physical box as Server 1.

       

      I've tested many permutations and interpretation of the manuals. With my 'best effort'...

       

      @MessageDriven(activationConfig = {

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

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

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

      @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:jboss/exported/jms/RemoteConnectionFactory"),

      @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=http-remoting://localhost;port=80")

      }, mappedName = "TestQueue")

       

      ...I'm getting this security exception.

      HQ224018: Failed to create session: HornetQSecurityException[errorType=SECURITY_EXCEPTION message=HQ119031: Unable to validate user: jms]

       

      ...which leads me to conclude Server2 isn't going 'Remote' for the queue - it's just looking inside itself.

      This is confirmed by changing to a user that only exists on Server2.

       

      I'm doing this in Wildfly 8.2.0 Final, downloaded fresh the other day.

      Both servers are running standalone-full, I have the vanilla definitions of ConnectionFactories etc.

       

      Can somebody please help me here.

       

      Many Thanks.

       

      KP

        • 1. Re: How to configure an MDB to read a queue on a remote Wildfly server.
          jbertram

          Couple of things:

          1. The "connectionFactoryLookup" activation configuration property is not valid for the HornetQ JCA RA.  I'm not sure where you got that.
          2. The value you're using for the "connectionParameters" activation configuration property is a mix of both HornetQ and Wildfly JNDI URL syntax.  The "host" should simply refer to a host (i.e. either IP address or DNS name) and not a URL. 
          3. I believe you should also add the "http-upgrade-enabled" property to your "connectionParameters" with a value of "true".  I'm not 100% sure on this point since I haven't attempted to use the HTTP port from a remote MDB before.
          4. You're missing the "connectorClassName" activation configuration property which in your case would need a value of "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory".  Without this it will default to "org.hornetq.core.remoting.impl.invm.InVMConnectorFactory" (i.e. connect to the in-vm server).
          1 of 1 people found this helpful
          • 2. Re: How to configure an MDB to read a queue on a remote Wildfly server.
            kevinprendergast

            Thanks Justin for your prompt response. As a work around I have deployed a JMS Bridge make the remote queue, local again.

            This has got me out of my pickle, but I will go back and process your advice and update the forum with findings.

             

                      <jms-bridge name="simple-jms-bridge">

                            <source>

                                <connection-factory name="ConnectionFactory"/>

                                <destination name="jms/queue/test1"/>

                            </source>

                            <target>

                                <connection-factory name="jms/RemoteConnectionFactory"/>

                                <destination name="jms/queue/test2"/>

                                <user>jms1</user>

                                <password>password</password>

                                <context>

                                    <property key="java.naming.factory.initial" value="org.jboss.naming.remote.client.InitialContextFactory"/>

                                    <property key="java.naming.provider.url" value="http-remoting://localhost:8180"/>

                                </context>

                            </target>

                            <quality-of-service>AT_MOST_ONCE</quality-of-service>

                            <failure-retry-interval>10000</failure-retry-interval>

                            <max-retries>-1</max-retries>

                            <max-batch-size>10</max-batch-size>

                            <max-batch-time>100</max-batch-time>

                        </jms-bridge>

             

            ...Bear with...

            KP

            • 3. Re: Re: How to configure an MDB to read a queue on a remote Wildfly server.
              kevinprendergast

              Justin, I've made some more tests following your comments, with variants of the extract below

               

              @MessageDriven(activationConfig = {

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

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

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

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

              @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=http-remoting://ec2-ww-xx-yy-zz.ap-southeast-2.compute.amazonaws.com;port=80;http-upgrade-enabled=true"),

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

              }, mappedName = "TestQueue")

               

              In most cases I get the exception HQ214016: Failed to create netty connection: java.nio.channels.UnresolvedAddressException

               

              I've briefly checked my standalone-full to be sure it's not got any junk in from my messing. But I may be guilty.

               

              In the meantime I'm going to advance with the JmsBridge - It get's me passed my problem - and it's actually a more robust solution. So don't go staying up late at night to work this out.

               

              But if you or anybody can spot what I've done wrong then feel free to point out my error.

               

              KP

              • 4. Re: Re: Re: How to configure an MDB to read a queue on a remote Wildfly server.
                jbertram

                You didn't change one of the things I mentioned in my previous comment.  I said, "The 'host' should simply refer to a host (i.e. either IP address or DNS name) and not a URL."  However, you are still using a URL.

                 

                Also, I missed one thing.  You should just use the HornetQ name of the destination rather than the JNDI name for the value of "destinationLookup".

                 

                To sum up, try this:

                 

                @MessageDriven(activationConfig = {
                @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "testQueue"),
                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                @ActivationConfigProperty(propertyName = "user", propertyValue = "jms"),
                @ActivationConfigProperty(propertyName = "password", propertyValue = "password"),
                @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=ec2-ww-xx-yy-zz.ap-southeast-2.compute.amazonaws.com;port=80;http-upgrade-enabled=true"),
                @ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory")
                }, mappedName = "TestQueue")
                

                 

                Lastly, I'm not sure why you think the JMS bridge is more robust than an MDB.  I wouldn't consider the JMS bridge to be more robust.  Both can retry in the case of failures.  Both can use XA. 

                 

                The benefit of using an MDB is performance.  With a JMS bridge you have a single consumer/producer moving messages.  With an MDB you have 15 sessions by default (configured via the "maxSession" activation configuration property) potentially consuming messages concurrently.  Also, with the bridge you have an additional "hop" (which would be especially costly in the case of XA) whereas with the MDB the message goes straight to the consumer.

                • 5. Re: How to configure an MDB to read a queue on a remote Wildfly server.
                  kevinprendergast

                  My underlying error was the HornetQ name.

                   

                  I'd convinced myself it was my connectionParameters that were the root of my demons - so sorry for showing you a doomed attempt with a URL.

                  The last summary configures an MDB that connects to a queue on a remote Wildfly server.

                  I do notice that the onMessage call appears to be a little more delayed than usual - but not really looked at this.

                   

                  Fair point on the JMS Bridge robustness and performance.

                   

                  Conclusions of this thread...

                  • Use the HornetQ Name.
                  • Don't pollute the host name with any http or remoting jibber-jabber.
                  • Justin is The Master.

                   

                  Many Thanks - Have a good weekend.

                   

                  KP

                  • 6. Re: How to configure an MDB to read a queue on a remote Wildfly server.
                    marcanthony

                    Hi Justin

                     

                    I have migrated to 2 wildfly 10 instances (from wildfy 8.2.0 and wildfly 9.0.1) before migration I had an mdb that consumed from a remote queue with following setup

                     

                            @ActivationConfigProperty(propertyName = "destination",

                                                      propertyValue = "qjndi"),

                            @ActivationConfigProperty(propertyName = "destinationType",

                                                      propertyValue = "javax.jms.Queue"),

                            @ActivationConfigProperty(propertyName = "maxSession",

                                                      propertyValue = "4"),

                            @ActivationConfigProperty(propertyName = "user",

                                                      propertyValue = "user"),

                            @ActivationConfigProperty(propertyName = "password",

                                                      propertyValue = "password"),

                            @ActivationConfigProperty(propertyName = "transactionTimeout",

                                                      propertyValue = "180"),

                            @ActivationConfigProperty(propertyName = "connectionParameters",

                                                      propertyValue = "host=host;port=8080;http-upgrade-enabled=true"), 

                            @ActivationConfigProperty(propertyName = "connectorClassName",

                                                      propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),

                     

                     

                    After the upgrade I changed the class name to

                     

                    org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory

                     

                    but if refuses to connect

                     

                    AMQ152005: Failure in broker activation org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.apache.activemq.artemis.ra.ActiveMQResourceAdapter@78712571 destination=MyQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=user password=**** maxSession=4): ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=AMQ119013: Timed out waiting to receive cluster topology. Group:null]

                     

                    any suggestions

                     

                    Thanks

                     

                    Marc

                    • 7. Re: How to configure an MDB to read a queue on a remote Wildfly server.
                      jbertram

                      This thread has already been marked as "answered" so please create a new one.  Thanks!