Example 16 shows the complete Spring 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 16. Camel JMS Component with XA Enabled
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
">
<!--
OSGi TM Service
-->
<!-- access through Spring's PlatformTransactionManager -->
<osgi:reference id="osgiPlatformTransactionManager"
interface="org.springframework.transaction.PlatformTransactionManager"/>
<!-- access through PlatformTransactionManager -->
<osgi:reference id="osgiJtaTransactionManager"
interface="javax.transaction.TransactionManager"/>
...
<!--
JMS TX endpoint configuration
-->
<bean id="jmstx"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsTxConfig" />
</bean>
<bean id="jmsTxConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsXaPoolConnectionFactory"/>
<property name="transactionManager" ref="osgiPlatformTransactionManager"/>
<property name="transacted" value="false"/>
<property name="cacheLevelName" value="CACHE_CONNECTION"/>
</bean>
<!-- connection factory wrapper to support auto-enlisting of XA resource -->
<bean id="jmsXaPoolConnectionFactory"
class="org.apache.activemq.pool.JcaPooledConnectionFactory">
<property name="maxConnections" value="1" />
<property name="connectionFactory" ref="jmsXaConnectionFactory" />
<property name="transactionManager" ref="osgiJtaTransactionManager" />
<property name="name" value="activemq.default" />
</bean>
<bean id="jmsXaConnectionFactory"
class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="vm:local?jms.prefetchPolicy.all=1"/>
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="0"/>
</bean>
</property>
</bean>
<!--
ActiveMQ XA Resource Manager
-->
<bean id="resourceManager"
class="org.apache.activemq.pool.ActiveMQResourceManager"
init-method="recoverResource">
<property name="transactionManager" ref="osgiJtaTransactionManager" />
<property name="connectionFactory" ref="jmsXaPoolConnectionFactory" />
<property name="resourceName" value="activemq.default" />
</bean>
...
</beans>The preceding Spring XML configuration can be explained as follows:
Define a reference to the OSGi service that exposes the
| ||||
Define a reference to the OSGi service that exposes the JTA
| ||||
The bean identified by the ID, | ||||
The | ||||
The
| ||||
The | ||||
In order for the Aries transaction manager to write its transaction log
properly (which is needed if you want to recover transactions after a crash), the
| ||||
The bean with the ID, | ||||
The 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 IP port In this example, the prefetch policy is set to | ||||
In this example, the redelivery policy is disabled by setting
| ||||
The |






![[Note]](imagesdb/note.gif)


