Limiting the scope of a transaction
The technique shown in the Using transactions with a database recipe used the transacted
DSL statement to initiate a transaction. Using this approach, the transaction is committed when the exchange's processing completes. This recipe will show you how you can control the scope of transactions in a much more granular fashion using the policy
statement.
Getting ready
The Java code for this recipe is located in the org.camelcookbook.transactions.transactionpolicies
package. The Spring XML files are located under src/main/resources/META-INF/spring
and prefixed with transactionPolicies
.
How to do it...
Set up a SpringTransactionPolicy
associated with a transaction manager as shown in the Using transactions with a database recipe.
Tip
The type of transaction manager is not relevant, as this approach applies to JDBC, JMS, and XA transactions.
Using the policy
DSL statement, wrap the individual processing steps that you want to enclose in a transaction, referring to...