1 2 Previous Next 15 Replies Latest reply on Feb 23, 2015 10:29 AM by jbertram

    I'm looking for an example of creating a consumer to a pooled-connection-factory.

    rsmith1

      The documentation for the Wildfly Messaging configuration states in part:

      JMS Connection Factories

      There are three kinds of basic JMS connection-factory that depends on the type of connectors that is used.

      ...

      • "It should only be used to send (i.e. produce) messages when looked up in JNDI or injected."

       

       

      We are using Message Listeners using the providerAdapterJNDI set to the JNDI name of the mdb, which I've seen in a number of examples.

       

      If it should not be done using JNDI, what is the recommended way of doing it?

      Below is an example of one of our mdbs:

       

      @javax.ejb.MessageDriven(name="myEJB", mappedName="myEJB", activationConfig = {

        @ActivationConfigProperty(propertyName="maxSession", propertyValue="1"),

        @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue = "Auto-acknowledge"),

        @ActivationConfigProperty(propertyName="destination", propertyValue="MY_QUEUE"),

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

        @ActivationConfigProperty(propertyName="providerAdapterJNDI", propertyValue="java:/JmsXA")

        })

      @TransactionManagement(TransactionManagementType.CONTAINER)

      public class MyEJB implements MessageListener

       

      An additional question - we have discovered that without the maxSession set to 1, we are not able to connect to the remote hornetQ server. Anyone know why?

       

      Thanks in advance,

      Bob Smith

        • 1. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
          jbertram

          Your current MDB (which uses the "providerAdapterJNDI" activation configuration property) is using the legacy JMS JCA Resource Adapter shipped with previous versions of JBoss AS.  This RA is no longer used to integrate with the JMS implementation (i.e. HornetQ) shipped in Wildfly.  In Wildfly you'd use the HornetQ JCA RA which is configured via <pooled-connection-factory>.  By default all MDBs will use this JCA RA.

           

          See the HornetQ documentation for the different activation configuration properties which are available.

          • 2. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
            rsmith1

            Hi Justin,

            Thanks for your quick response. Are you saying we do not need the providerAdapterJNDI at all? Just use annotation @ResourceAdapter("hornetq-ra.rar")?

            I will try that. Would you know why we have to set maxSession=1?
            When we were using a different connection factory it worked with the default max session which I believe is 15.

            Thanks,

            Bob

            • 3. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
              jbertram

              Are you saying we do not need the providerAdapterJNDI at all?

              That's correct.  The HornetQ JCA RA doesn't recognize/use the "providerAdapterJNDI" activation configuration property.

               

              Just use annotation @ResourceAdapter("hornetq-ra.rar")?

              You don't even need to do that much if you don't want to.  Your MDB will use the HornetQ JCA RA by default (courtesy of the resource-adapter-ref in the ejb3 subsystem).

               

              Would you know why we have to set maxSession=1?

              The maxSession shouldn't have any bearing on whether or not you can connect to HornetQ.

               

              When we were using a different connection factory it worked with the default max session which I believe is 15.

              I'm not clear on what you mean here.  Please elaborate.

              • 4. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                rsmith1

                We have a pooled-connection-factory that is setup to connect to a master/slave hornetq pair.
                Previously, we were using a setup with a coresident hornetq server and created connection factories (not pooled connection factory) for our mdbs.

                Our mdb's did not have maxSession set on them and should have been controlled by the app server settings for message driven beans (15)

                The mdbs worked fine in that scenario.

                Now that we are using the pooled connection factory, if we do not include the maxSession=1, we get messages 'Attempting to connect to ...."

                We put statements in our constructors and @PostConstruct messages and our logs show wildlfy just creating view endpoint pairs continually.

                Once we set maxSession=1, we get a 'Connected to HornetQ' message after the 'Attempting' message and only a single view endpoint pair is created at startup.

                • 5. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                  jbertram

                  We have a pooled-connection-factory that is setup to connect to a master/slave hornetq pair.

                  Can you cut/paste this pooled-connection-factory configuration?

                   

                  Previously, we were using a setup with a coresident hornetq server and created connection factories (not pooled connection factory) for our mdbs.

                  By "coresident" I assumed you mean the HornetQ server was local (i.e. running in the same JVM as the application server).  Is that correct?

                   

                  Also, in what way did you create connection factories for your MDBs and what specifically did you use these connection factories for (e.g. consuming, producing)?

                   

                  Our mdb's did not have maxSession set on them and should have been controlled by the app server settings for message driven beans (15)

                  To be clear, the default value for the "maxSession" activation configuration property is controlled by the HornetQ JCA RA itself rather than the application server.

                   

                  Now that we are using the pooled connection factory, if we do not include the maxSession=1, we get messages 'Attempting to connect to ...."

                  In what capacity are you using the pooled connection factory now (e.g. consuming, producing)?  Can you include specific log snippets of the messages you receive in this scenario?

                   

                  Also, can you cut/paste your full MDB configuration?

                  • 6. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                    rsmith1

                    1. pooled-connection-factory configuration:
                      <pooled-connection-factory name="hornetq-ra">

                                                <transaction mode="xa"/>

                                                <user>******</user>

                                                <password>******</password>

                                                <connectors>

                                                    <connector-ref connector-name="messaging-remote-connector-1"/>

                                                    <connector-ref connector-name="messaging-remote-connector-2"/>

                                                </connectors>

                                                <entries>

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

                                                    <entry name="java:jboss/DefaultJMSConnectionFactory"/>

                                                    <entry name="java:jboss/exported/JmsXA"/>

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

                                                </entries>

                                                <ha>true</ha>

                                                <failover-on-server-shutdown>true</failover-on-server-shutdown>

                                            </pooled-connection-factory>
                    2. Yes the hornetq was local
                    3. We created a connection factory using "in-vm"
                    4. We are using both producers and consumers.
                    5. Log snippets with session equal to 1:

                    server log

                    2015-02-18 08:02:03,520 INFO  [org.hornetq.ra] (default-threads - 42) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@44c2fcca destination=java:jboss/exported/jms/HISTORY_QUEUE destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=1)

                    2015-02-18 08:02:03,531 INFO  [org.hornetq.ra] (default-threads - 42) HQ151002: Reconnected with HornetQ

                     

                     

                    6. server log when we have multiple sessions:

                    2015-02-18 08:45:43,430 INFO  [org.hornetq.ra] (default-threads - 45) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@44c2fcca destination=java:jboss/exported/jms/HISTORY_QUEUE destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=2)

                    we never get a Reconnected message

                     

                    7. App Log when we dont connect:

                    2015-02-18 08:45:41,423 [default-threads - 45] INFO  c.hbfgroup.core.history.HistoryBean - Creating history bean instance.com.hbfgroup.core.history.HistoryBean$$$view206@15a85ca4

                    2015-02-18 08:45:41,427 [default-threads - 45] INFO  c.hbfgroup.core.history.HistoryBean - Creating history bean instance.com.hbfgroup.core.history.HistoryBean$$$endpoint47@2c9c6db1

                    2015-02-18 08:45:43,435 [default-threads - 45] INFO  c.hbfgroup.core.history.HistoryBean - Creating history bean instance.com.hbfgroup.core.history.HistoryBean$$$view206@5ddf3ecc

                    2015-02-18 08:45:43,436 [default-threads - 45] INFO  c.hbfgroup.core.history.HistoryBean - Creating history bean instance.com.hbfgroup.core.history.HistoryBean$$$endpoint47@6b93f339

                    2015-02-18 08:45:45,446 [default-threads - 45] INFO  c.hbfgroup.core.history.HistoryBean - Creating history bean instance.com.hbfgroup.core.history.HistoryBean$$$view206@5f5e7171

                    continues until we undeploy
                    ,..

                    • 7. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                      jbertram

                      The first thing I notice is that you're using a JNDI name like "java:jboss/exported/jms/HISTORY_QUEUE" to connect to an ostensibly remote queue.  I wouldn't expect that to work under any circumstances.  If you have a remote queue with an <entry> of "java:jboss/exported/jms/HISTORY_QUEUE" then a remote client (like your MDB) would use "jms/HISTORY_QUEUE" to look it up since that is the part of the name that is actually exported to remote clients.

                      • 8. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                        rsmith1

                        I will try that, but I think we ended up with the name via trial and error. I know the producers all use the HORNETQ name and not the jms name via the createQueue method.

                        • 9. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                          jbertram

                          The MDB can use the HornetQ name as well.  No need to use JNDI if you don't want/have to.

                          • 10. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                            rsmith1

                            Hi Justin,

                            Thanks for the recommendations. They worked.

                            The one last issue we have remaining is pertaining to hooking ExceptionListeners to producers to the pooled-connection-factory.

                            When we attempt to create one we get the follow errors. I think its related to the pool being 'xa' but I dont know how to get around it.

                             

                            javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
                            2015-02-19 at org.hornetq.ra.HornetQRASessionFactoryImpl.setExceptionListener(HornetQRASessionFactoryImpl.java:635)

                             

                            Here's how we've implemented it:

                             

                                        ctx = new InitialContext();

                                        QueueConnectionFactory wlConnectionFactory = (QueueConnectionFactory)ctx.lookup("java:/JmsXA");

                                        wlConnection = wlConnectionFactory.createQueueConnection();

                                        wlSession = wlConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

                                       

                                        Queue wlQueue = wlSession.createQueue(wlQueueName); //NAME of the QUEUE, not JNDI NAME

                                        wlSender = wlSession.createSender(wlQueue);

                                      //this is commented out because it causes an error....  we dont need an exception listener just need to reconnect when we fail to send

                                        //  wlConnection.setExceptionListener(new WLExceptionListener());                     

                                        wlConnection.start();

                             

                            Thanks,

                            Bob

                            • 11. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                              jbertram

                              Couple of things:

                              1. Setting an ExceptionListener on a connection from within a container-managed component (e.g. an MDB) is indeed disallowed by the Java EE specification.  It's not related to XA.
                              2. Connections coming from a pooled-connection-factory (i.e. the HornetQ JCA RA) already have an ExceptionListener registered that will deal with connection failures.  That's one of the benefits of using container-managed resources.
                              3. It doesn't make sense to set an ExceptionListener on a connection that's only used to send messages anyway.  ExceptionListeners are specifically designed to receive failure notifications asynchronously on connections which are used to consume messages (e.g. those used by asynchronous MessageListener implementations).  Furthermore, as the JMS 1.1 specification states in section 4.3.8, "The exceptions delivered to ExceptionListener are those that have no other place to be reported. If an exception is thrown on a JMS call it, by definition, must not be delivered to an ExceptionListener (in other words, ExceptionListener is not for the purpose of monitoring all exceptions thrown by a connection)."  In other words, anytime you call a method on your producer the implementation has an opportunity to report a problem to the caller (i.e. throw an exception) so the ExceptionListener would never be called.
                              1 of 1 people found this helpful
                              • 12. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                                rsmith1

                                We will look at a different way. Thanks for your time.

                                • 13. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                                  jbertram

                                  Just to be clear, you will look for a different way to do what?

                                  • 14. Re: I'm looking for an example of creating a consumer to a pooled-connection-factory.
                                    rsmith1

                                    Instead of using an ExceptionListener we will look to doing safety checks in our exception blocks when sending messages.

                                    1 2 Previous Next