10 Replies Latest reply on Jun 23, 2015 1:19 PM by swany

    How to use hornetq-ra.rar on Wildfly

    sridharthiyagarajan

      Hello,

       

      I am migrating my application from JBoss 6 to Wildfly 8 with standalone-full-ha.xml configuration.

       

      MDB in my application uses  jms-ra.rar as resource adapter and the rar archive is present in server/deploy directory  with respect to deployment in JBoss 6 Application Server. In Wildfly, I have defined hornetq-ra.rar as the resource adapter in my MDB (@ResourceAdapter(value="hornetq-ra.rar").

       

      Is hornetq-ra.rar a default resource adapter in Wildfly ? Is adding @ResourceAdapter(value="hornetq-ra.rar" in my MDB enough to consume this default resource adapter ?.

       

      I cannot find hornetq-ra.rar files structure in Wildfly Application Server but just observed one module org.hornetq.ra. Is this module responsible for hornetq-ra.rar ? Do we need to add this module as a dependency to consume default resource adapter ?

       

      MDB code snippet:

       

      @TransactionManagement(TransactionManagementType.CONTAINER)

      @TransactionAttribute(TransactionAttributeType.REQUIRED)

      @MessageDriven(name = "TestMessageDrivenBean", activationConfig = {

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

              @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/TestQueue")})

      @ResourceAdapter(value="hornetq-ra.rar")

      public class TestMDBean implements MessageListener {

      ...

      }

       

      1. hornetq-ra.rar is a default resource adapter and hence, below section is not modified.

      <subsystem xmlns="urn:jboss:domain:resource-adapters:2.0"/>

       

      2. Defined TestQueue in the messaging section as defined below.

       

      <subsystem xmlns="urn:jboss:domain:messaging:2.0">

                  <hornetq-server>

                      ....

       

                      <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="http-connector"/>

                              </connectors>

                              <entries>

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

                              </entries>

                              <ha>true</ha>

                              <block-on-acknowledge>true</block-on-acknowledge>

                              <reconnect-attempts>-1</reconnect-attempts>

                          </connection-factory>

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

                              <transaction mode="xa"/>

                              <connectors>

                                  <connector-ref connector-name="in-vm"/>

                              </connectors>

                              <entries>

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

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

                              </entries>

                          </pooled-connection-factory>

                      </jms-connection-factories>

       

                      <jms-destinations>

                          <jms-queue name="ExpiryQueue">

                              <entry name="java:/jms/queue/ExpiryQueue"/>

                          </jms-queue>

                          <jms-queue name="DLQ">

                              <entry name="java:/jms/queue/DLQ"/>

                          </jms-queue>

                          <jms-queue name="TestQueue">

                              <entry name="java:/jms/queue/TestQueue"/>

                          </jms-queue>

                      </jms-destinations>

                  </hornetq-server>

              </subsystem>

       

      3. Adding the available default binding under <subsystem xmlns="urn:jboss:domain:ee:2.0">.

       

      <default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:/TestDB" jms-connection-factory="java:jboss/DefaultJMSConnectionFactory" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>

       

      What is the connection factory name for consuming the queue created using hornetq-ra.rar adapter ? Is it java:jboss/DefaultJMSConnectionFactory as this is defined in default bindings or do I need to consider other JNDI names java:/JmsXA , java:/ConnectionFactory for initializing the JMS. Please help. Many thanks.

        • 1. Re: How to use hornetq-ra.rar on Wildfly
          jbertram

          Is hornetq-ra.rar a default resource adapter in Wildfly ?

          Yes, the HornetQ JCA RA is the default RA used for MDBs in Wildfly.  See this bit of configuration in the ejb3 subsystem:

           

          <mdb>
              <resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:hornetq-ra.rar}"/>
              <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
          </mdb>
          

           

          This sets the default value for all MDBs which don't specify their own JCA RA.

           

          Is adding @ResourceAdapter(value="hornetq-ra.rar" in my MDB enough to consume this default resource adapter ?.

          That annotation is not required.  All MDBs will use the HornetQ JCA RA by default (due to the configuration referenced above).

           

          I cannot find hornetq-ra.rar files structure in Wildfly Application Server but just observed one module org.hornetq.ra. Is this module responsible for hornetq-ra.rar ? Do we need to add this module as a dependency to consume default resource adapter ?

          The hornetq-ra.rar doesn't exist as an actual file on the file-system.  The RA is essentially constructed programmatically by the messaging subsystem.  The resource-adapter-name "hornetq-ra.rar" refers to the pooled-connection-factory named "hornetq-ra" in the messaging subsystem.

           

          No, you do not need to add that module as a dependency to use the HornetQ JCA RA.

           

          What is the connection factory name for consuming the queue created using hornetq-ra.rar adapter ? Is it java:jboss/DefaultJMSConnectionFactory as this is defined in default bindings or do I need to consider other JNDI names java:/JmsXA , java:/ConnectionFactory for initializing the JMS. Please help. Many thanks.

          I'm not really sure what you're asking here.  Hopefully my previous answers provide you enough help to resolve your problems otherwise please clarify.

          • 2. Re: How to use hornetq-ra.rar on Wildfly
            sridharthiyagarajan

            Many thanks for a brief explanation... Justin. I understood. Regarding my last point, PFB the code snippet which is used to get the Connection Factory object (QueueConnectionFactory)  and the JNDI name referred for fetching from initial content is java:/ConnectionFactory.

             

            InitialContext initialContext = new InitialContext();

            Object objRef = initialContext.lookup("java:/ConnectionFactory");

            QueueConnectionFactory cachedConnectionFactory = (QueueConnectionFactory) objRef;

            cachedQueueConnection = cachedConnectionFactory.createConnection();

             

            With this given statement by you, "The resource-adapter-name "hornetq-ra.rar" refers to the pooled-connection-factory named "hornetq-ra" in the messaging subsystem.", is the JNDI lookup name for getting Connection Factory object (QueueConnectionFactory) same (which is java:/ConnectionFactory) OR do the JNDI names (java:/JmsXA, java:jboss/DefaultJMSConnectionFactory) present in pooled connection factory hornetq-ra (<pooled-connection-factory name="hornetq-ra">) need to used for lookup.  Thanks.

            • 3. Re: How to use hornetq-ra.rar on Wildfly
              sridharthiyagarajan

              Hi Justin.. I missed adding about the ports. I took the below port configurations from hornetq configuration XML file from JBoss 6 AS. Do I need to add the below ports in standalone-full-ha.xml for messaging or is this not at all required ?

               

              <socket-binding name="messaging" port="5445"/>

              <socket-binding name="messaging-throughput" port="5455"/>


              Thanks for your help.

              • 4. Re: How to use hornetq-ra.rar on Wildfly
                jbertram

                With this given statement by you, "The resource-adapter-name "hornetq-ra.rar" refers to the pooled-connection-factory named "hornetq-ra" in the messaging subsystem.", is the JNDI lookup name for getting Connection Factory object (QueueConnectionFactory) same (which is java:/ConnectionFactory) OR do the JNDI names (java:/JmsXA, java:jboss/DefaultJMSConnectionFactory) present in pooled connection factory hornetq-ra (<pooled-connection-factory name="hornetq-ra">) need to used for lookup.  Thanks.

                If you want to get a reference to a pooled-connection-factory then you need to use the specific JNDI name for that pooled-connection-factory.  In this instance, you'd use java:/JmsXA or java:jboss/DefaultJMSConnectionFactory.  If you use java:/ConnectionFactory you'll get a reference to the "InVmConnectionFactory" connection-factory which is just a plain JMS connection factory (i.e. it has no pooling or other JCA functionality like automatic JTA transaction enlistment).  What connection factory you use really depends on your use-case.  Try reading the documentation on this for more help.  It discusses the different types of connection factories and which is suitable for which use-case.

                1 of 1 people found this helpful
                • 5. Re: How to use hornetq-ra.rar on Wildfly
                  jbertram

                  If you're using standalone-full.xml or standalone-full-ha.xml then you shouldn't need to add anything to the configuration to have basic JMS functionality for either local or remote clients.

                  1 of 1 people found this helpful
                  • 6. Re: How to use hornetq-ra.rar on Wildfly
                    sridharthiyagarajan

                    Many thanks .. Justin. Your comments helped me to move further. I read the documentation and using the JNDI java:comp/DefaultJMSConnectionFactory initializes the JMS connection fine. Also, the discussion I'm looking for an example of creating a consumer to a pooled-connection-factory. helped out to comment the below line of code to avoid the error javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6.

                     

                    cachedQueueConnection.setExceptionListener(new ExceptionJMSListenerImpl());


                    Now, am facing the below exception when ObjectMessage objMsg = (ObjectMessage) msg; Context c = (Context) objMsg.getObject(); lines are executed. Is the server looking into org.hornetq module for the class Context which is a part of application ?

                     

                     

                    ERROR [org.hornetq.ra] (Thread-6 (HornetQ-client-global-threads-7368628)) HQ154004: Failed to deliver message: javax.jms.JMSException: com.test.util.context.Context from [Module "org.hornetq:main" from local module loader @180072b (finder: local module finder @56c5f4 (roots: D:\wildfly-8.2.0.Final\modules,D:\wildfly-8.2.0.Final\modules\system\layers\base))]


                    Please help me. Thanks.

                    • 7. Re: How to use hornetq-ra.rar on Wildfly
                      sridharthiyagarajan

                      Hello Justin.. the above issue which I mentioned was due to class loader issue and I solved it. Many thanks for the guidance and your comments are really valuable. Thanks again ..

                      • 8. Re: How to use hornetq-ra.rar on Wildfly
                        swany

                        Justin,

                         

                        Is it possible to set attributes on this hornetq-ra "faux resource adapter?" for example, to change the default maxSession count from 15 to something else? (this is what we really want to be able to do via standalone.xml to match our widely varying server configurations).


                        Thanks,

                         

                        Mark

                        • 9. Re: How to use hornetq-ra.rar on Wildfly
                          jbertram

                          No, maxSession can only be configured on the MDB itself via annotation or deployment descriptor.

                          • 10. Re: How to use hornetq-ra.rar on Wildfly
                            swany

                            Thanks, Justin.