Red Hat Training

A Red Hat training course is available for Red Hat Fuse

7.3. Sample JMS XA Configuration

Spring XML configuration

Example 7.1, “Camel JMS Component with XA Enabled” shows the complete Blueprint XML configuration required to initialize the jmstx Camel JMS component with XA transactions. After setting up the Camel JMS component with this code, you can create a transactional JMS endpoint in a route using a URL like jmstx:queue:QueueName.

Example 7.1. Camel JMS Component with XA Enabled

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns=""

        OSGi TM Service
    <!-- access through Spring's PlatformTransactionManager -->
    <reference id="osgiPlatformTransactionManager"
        interface="org.springframework.transaction.PlatformTransactionManager"> 1
    <!-- access through PlatformTransactionManager -->
    <reference id="recoverableTxManager"
        interface="org.apache.geronimo.transaction.manager.RecoverableTransactionManager" availability="mandatory"> 2
        JMS TX endpoint configuration
    <bean id="jmstx"
          class="org.apache.activemq.camel.component.ActiveMQComponent"> 3
        <property name="configuration" ref="jmsTxConfig"> 
    <bean id="jmsTxConfig"
          class="org.apache.camel.component.jms.JmsConfiguration"> 4
        <property name="connectionFactory" ref="jmsXaPoolConnectionFactory"> 
        <property name="transactionManager" ref="osgiPlatformTransactionManager"> 
        <property name="transacted" value="false">
        <property name="cacheLevelName" value="CACHE_CONNECTION">
    <!-- connection factory wrapper to support auto-enlisting of XA resource -->
    <bean id="jmsXaPoolConnectionFactory"
          class="org.apache.activemq.pool.JcaPooledConnectionFactory"> 5
        <property name="name" value="MyXaResourceName">
        <property name="maxConnections" value="1"> 6
        <property name="connectionFactory" ref="jmsXaConnectionFactory">
        <property name="transactionManager" ref="recoverableTxManager">
    <bean id="jmsXaConnectionFactory"
          class="org.apache.activemq.ActiveMQXAConnectionFactory"> 7
        <property name="brokerURL" value="vm:local"> 8
        <property name="userName" value="UserName">
        <property name="password" value="Password">
        <property name="redeliveryPolicy"> 9
            <bean class="org.apache.activemq.RedeliveryPolicy">
                <property name="maximumRedeliveries" value="0">
        ActiveMQ XA Resource Manager
    <bean id="resourceManager"
        <property name="transactionManager" ref="recoverableTxManager">
        <property name="connectionFactory" ref="jmsXaConnectionFactory">
        <property name="resourceName" value="activemq.default"> 10

Listing notes

The preceding Spring XML configuration can be explained as follows:
Define a reference to the OSGi service that exposes the PlatformTransactionManager interface of the OSGi container's built-in XA transaction manager. This service can then be accessed through the bean ID, osgiPlatformTransactionManager.
Define a reference to the OSGi service that exposes the recoverable TransactionManager interface of the OSGi container's built-in XA transaction manager. This service can then be accessed through the bean ID, recoverableTxManager.
The bean identified by the ID, jmstx, is the ActiveMQ implementation of the Camel JMS component. You can use this component to define transactional JMS endpoints in your routes. The only property that you need to set on this bean is a reference to the JmsConfiguration bean with the ID, jmsTxConfig.
The JmsConfiguration bean with the ID, jmsTxConfig, is configured as described in Section 7.1, “Enabling XA on the Camel JMS Component”. In particular, the configuration bean gets a reference to the XA pooled connection factory and a reference to the osgiPlatformTransactionManager bean. The transacted property must be set to false.
The JcaPooledConnectionFactory is a wrapper class that adds extra capabilities to the basic connection factory bean (that is, it adds the capabilities to auto-enlist XA resources and to pool JMS connections).
The maxConnections property should be set to 1.
The bean with the ID, jmsXaConnectionFactory, is the basic connection factory, which encapsulates the code for connecting to the JMS broker. In this case, the bean is an instance of ActiveMQXAConnectionFactory type, which is a special connection factory class that you must use when you want to connect to the ActiveMQ broker with support for XA transactions.
The brokerURL property defines the protocol for connecting to the broker. In this case, the vm:local URL connects to the broker that is embedded in the current JVM and is identified by the name local (the configuration of the embedded broker is not shown in this example).
There are many different protocols supported by Apache ActiveMQ that you could use here. For example, to connect to a remote broker through the OpenWire TCP protocol listening on TCP port 61616 on host MyHost, you would use the broker URL, tcp://MyHost:61616.
In this example, the redelivery policy is disabled by setting maximumRedeliveries to 0. Typically, you would not use a redelivery policy together with transactions. An alternative approach would be to define an exception handler that routes failed exchanges to a dead letter queue.
The resourceName property is the key entry that maps from the transaction manager log to a real-world XAResource object. It must be unique for each XAResource object.