9 Replies Latest reply on Oct 3, 2013 9:58 AM by Justin Bertram

    JMS Remote Consumer and <pooled-connection-factory>

    Lukasz Antoniak Newbie

      Hello Community!

       

      I have been playing with remote JMS producer and consumer for a while. The producer code can be easily developed and allows storing details of remote queue location in standalone or domain configuration files (see https://community.jboss.org/message/722711). Annotations of my initial Message-Driven Bean look as follows.

       

      @MessageDriven(

           name="ConsumerMdb",

           activationConfig = {

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

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

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

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

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

                @ActivationConfigProperty(propertyName="connectionParameters", propertyValue = "host=192.168.117.159;port=5445")

      })

       

      Furthermore, MDB configuration can be moved to ejb-jar.xml (see https://issues.jboss.org/browse/AS7-3816) and there lookup system properties.

       

      The bottom line question: why it is not advised to bind JMS consumers to pooled-connection-factory? This was clearly stated by Justin Bertram here: https://community.jboss.org/message/722711. What are the consequences? With such setup, I am able to use one connection factory for inbound and outbound traffic (http://rpokhodzhai.blogspot.com/2012/07/jboss-7-remote-jms-topic-mdb-consumer.html).

       

      @ResourceAdapter("ConnectionFactory1")

      @MessageDriven(

           name="ConsumerMdb",

           activationConfig = {

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

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

      })

       

      "ConnectionFactory1" is the same connection factory used by producer and consumer components.

       

      <connector name="remote-jms">

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

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

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

      </connector>

       

      <pooled-connection-factory name="ConnectionFactory1">

           <user>jmsuser</user>

           <password>jmspassword</password>

           <connectors>

                <connector-ref connector-name="remote-jms" />

           </connectors>

           <entries>

                <entry name="java:/ConnectionFactory1" />

           </entries>

      </pooled-connection-factory>

       

      Regards,

      Lukasz

        • 1. Re: JMS Remote Consumer and <pooled-connection-factory>
          Justin Bertram Master

          My note about consumers not using a <pooled-connection-factory> in the other thread was not aimed at MDBs.  It was aimed at unmanaged consumers running with the container (which itself isn't ideal since you lose all the power of Java EE (e.g. transactions, free resource pooling, security, etc.)).

           

          An MDB always uses a <pooled-connection-factory> - at least the inbound part of it that gets created under-the-covers. 

          • 2. Re: JMS Remote Consumer and <pooled-connection-factory>
            Lukasz Antoniak Newbie

            Hello Justin,

             

            Thank you for the quick and helpful answer. So to summarize, the following implementation of two approaches of consuming messages from remote queue is correct? Again, thanks a lot!

             

            JBoss configuration:

            <connectors>

                      <connector name="remote-jms-nonmgmt">

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

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

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

                      </connector>

                      <netty-connector name="remote-jms-mgmt" socket-binding="remote-jms-binding"/>

            </connectors>

            <connection-factory name="ConnectionFactory1NonMgmt">

                      <connectors>

                                <connector-ref connector-name="remote-jms-nonmgmt"/>

                      </connectors>

                      <entries>

                                <entry name="java:/ConnectionFactory1NonMgmt"/>

                      </entries>

            </connection-factory>

            <pooled-connection-factory name="ConnectionFactory1Mgmt">

                      <user>jmsuser</user>

                      <password>jmspassword</password>

                      <connectors>

                                <connector-ref connector-name="remote-jms-mgmt"/>

                      </connectors>

                      <entries>

                                <entry name="java:/ConnectionFactory1Mgmt"/>

                      </entries>

            </pooled-connection-factory>

             

            MDB:

            @ResourceAdapter("ConnectionFactory1Mgmt")

            @MessageDriven(

                 name="ConsumerMdb",

                 activationConfig = {

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

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

            })

             

            Manually consuming messages from EJB (inside container):

            InitialContext context = new InitialContext();

            ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup( "ConnectionFactory1NonMgmt" );

            Connection connection = connectionFactory.createConnection( "jmsuser", "jmspassword" );

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

            Queue queue = session.createQueue( "RemoteQueue1" );

            MessageConsumer consumer = session.createConsumer( queue );

            connection.start();

            Message message = consumer.receive();

             

            Regards,

            Lukasz

            • 4. Re: JMS Remote Consumer and <pooled-connection-factory>
              Arjun A Newbie

              hi ,

              I am also trying the same ,but i have a doubt, how to configure ConnectionFactory1Mgmt in producer side stanalone-full.xml

               

              @ResourceAdapter("ConnectionFactory1Mgmt")


              thanks in advance

               

               

               

               

               


              • 5. Re: JMS Remote Consumer and <pooled-connection-factory>
                Jiorgos Janik Newbie

                But all of this configuration has to do if you are using hornet. What about a third party JMS provider?

                • 6. Re: JMS Remote Consumer and <pooled-connection-factory>
                  Justin Bertram Master

                  Generally speaking, you'd use the third-party JMS provider's JCA RA to integrate.

                  • 7. Re: JMS Remote Consumer and <pooled-connection-factory>
                    Justin Bertram Master

                    If you want to use ConnectionFactory1Mgmt from a producer running in the application server than just look it up in JNDI or inject it.

                    • 8. Re: JMS Remote Consumer and <pooled-connection-factory>
                      Jiorgos Janik Newbie

                      The lookup of the ConnectionFacotry through JNDI from and EJB with injection lead to an exception. An MDB which consumes over the same factory works.The ConectionFactory has been defined in the standalone-full.xml for the provided rar.

                      • 9. Re: JMS Remote Consumer and <pooled-connection-factory>
                        Justin Bertram Master

                        I think you'd be better served by starting a new thread about this issue since this thread has already been marked as answered.