Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Transactional ClientCamel recommends supporting the Transactional Client from the EIP patterns using spring transactions. Transaction Oriented Endpoints like JMS support using a transaction for both inbound and outbound message exchanges. Endpoints that support transactions will participate in the current transaction context that they are called from. The redelivery in transacted mode is not handled by Camel but by the backing system (the transaction manager). In such cases you should resort to the backing system how to configure the redelivery. You should use the SpringRouteBuilder to setup the routes since you will need to setup the spring context with the TransactionTemplates that will define the transaction manager configuration and policies. For inbound endpoint to be transacted, they normally need to be configured to use a Spring PlatformTransactionManager. In the case of the JMS component, this can be done by looking it up in the spring context. You first define needed object in the spring configuration. Then you look them up and use them to create the JmsComponent. Transaction PoliciesOutbound 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: Then in your SpringRouteBuilder, you just need to create new SpringTransactionPolicy objects for each of the templates. Once created, you can use the Policy objects in your processing routes: OSGi BlueprintIf you are using OSGi Blueprint then you most likely have to explicit declare a policy and refer to the policy from the transacted in the route. And then refer to "required" from the route: Database SampleIn this sample we want to ensure that two endpoints is under transaction control. These two endpoints inserts data into a database. First of all we setup the usual spring stuff in its configuration file. Here we have defined a DataSource to the HSQLDB and a most importantly the Spring DataSource TransactionManager that is doing the heavy lifting of ensuring our transactional policies. You are of course free to use any of the Spring based TransactionManager, eg. if you are in a full blown J2EE container you could use JTA or the WebLogic or WebSphere specific managers. As we use the new convention over configuration we do not need to configure a transaction policy bean, so we do not have any JMS SampleIn this sample we want to listen for messages on a queue and process the messages with our business logic java code and send them along. Since its based on a unit test the destination is a mock endpoint. First we configure the standard Spring XML to declare a JMS connection factory, a JMS transaction manager and our ActiveMQ component that we use in our routing. When a route is marked as transacted using transacted Camel will automatic use the TransactionErrorHandler as Error Handler. It supports basically the same feature set as the DefaultErrorHandler, so you can for instance use Exception Clause as well. Integration Testing with SpringAn Integration Test here means a test runner class annotated When following the Spring Transactions documentation it is tempting to annotate your integration test with Instead, remove the Spring's transactional model ensures each transaction is bound to one thread. A Camel route may invoke additional threads which is where the blockage may occur. This is not a fault of Camel but as the programmer you must be aware of the consequences of beginning a transaction in a test thread and expecting a separate thread created by your Camel route to be participate, which it cannot. You can, in your test, mock the parts that cause separate threads to avoid this issue. Using multiple routes with different propagation behaviorsAvailable as of Camel 2.2
This is configured in the Spring XML file: See Also |