Google+ Followers

Thursday, April 9, 2015

Creating a JMS Bridge with XA on JBoss EAP 6.3

In case you want to create a JMS Bridge supporting XA on JBoss EAP 6.3 here are some hints on how to achieve this. I'm using HornetQ and ActiveMQ (with resource-adapter version 5.11.1) througout the example with queue A and C residing on ActiveMQ and a queue B on HornetQ, messages will be bridged from queue A to B to C.

In standalone configuration file add the following admin-object to the resource-adapter configuration for ActiveMQ:
<admin-object class-name="org.apache.activemq.ActiveMQXAConnectionFactory" jndi-name="java:/AMQXAConnectionFactory" enabled="true" use-java-context="true" pool-name="AMQXAConnectionFactory">
     <config-property name="brokerURL">
                                failover:(tcp://localhost:61616)?jms.rmIdFromConnectionId=true&amp;maxReconnectAttempts=0&amp;jms.xaAckMode=2&amp;jms.userName=admin&amp;jms.password=redhat
      </config-property>
 </admin-object>
You also need to do a modification to the ra.xml of the ActiveMQ resource-adapter consisting of adding the following:

<adminobject>
          <adminobject-interface>javax.jms.XAConnectionFactory</adminobject-interface>
          <adminobject-class>org.apache.activemq.ActiveMQXAConnectionFactory</adminobject-class>
          <config-property>
            <config-property-name>brokerURL</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
          </config-property>
</adminobject>

In the messaging subsystem add the following after hornetq-server:

<jms-bridge name="activemq-hornetq">
     <source>
           <connection-factory name="AMQXAConnectionFactory"/>
           <destination name="queue/queueA"/>
      </source>
      <target>
            <connection-factory name="XAConnectionFactory"/>
            <destination name="queue/queueB"/>
       </target>
       <quality-of-service>ONCE_AND_ONLY_ONCE</quality-of-service>
       <failure-retry-interval>1000</failure-retry-interval>
       <max-retries>-1</max-retries>
       <max-batch-size>1</max-batch-size>
       <max-batch-time>100</max-batch-time>
</jms-bridge>
<jms-bridge name="hornetq-activemq">
       <source>
             <connection-factory name="XAConnectionFactory"/>
             <destination name="queue/queueB"/>
       </source>
       <target>
             <connection-factory name="AMQXAConnectionFactory"/>
             <destination name="queue/queueC"/>
       </target>
       <quality-of-service>ONCE_AND_ONLY_ONCE</quality-of-service>
       <failure-retry-interval>1000</failure-retry-interval>
       <max-retries>-1</max-retries>
       <max-batch-size>1</max-batch-size><max-batch-time>100</max-batch-time>
 </jms-bridge>

Now your JMS bridge is ready to operate!