Transaction Policies - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

Outbound endpoints will automatically enlist in the current transaction context. But what if you do not want your outbound endpoint to enlist in the same transaction as your inbound endpoint? The solution is to add a Transaction Policy to the processing route. You first have to define transaction policies that you will be using. The policies use a Spring TransactionTemplate under the covers for declaring the transaction demarcation to use. So you will need to add something like the following to your Spring XML:

<bean id="PROPAGATION_REQUIRED" 
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
   <property name="transactionManager" ref="jmsTransactionManager"/>
</bean>

<bean id="PROPAGATION_REQUIRES_NEW" 
   class="org.apache.camel.spring.spi.SpringTransactionPolicy">
   <property name="transactionManager" ref="jmsTransactionManager"/>
   <property name="propagationBehaviorName" 
      value="PROPAGATION_REQUIRES_NEW"/>
</bean>

Then in your SpringRouteBuilder, you just need to create new SpringTransactionPolicy objects for each of the templates.

public void configure() {
   ...
   Policy requried = bean(SpringTransactionPolicy.class, 
       "PROPAGATION_REQUIRED"));
   Policy requirenew = bean(SpringTransactionPolicy.class, 
       "PROPAGATION_REQUIRES_NEW"));
   ...
}

Once created, you can use the Policy objects in your processing routes:

// Send to bar in a new transaction
from("activemq:queue:foo").policy(requirenew).to("activemq:queue:bar");

// Send to bar without a transaction.
from("activemq:queue:foo").policy(notsupported ).
   to("activemq:queue:bar");