Rolling back a transaction

So far we have seen transaction success or failure determined naturally—that is, by whether an exchange was successfully processed, or if an exception was thrown during its processing. This recipe will provide you with a number of additional options around controlling transaction rollback.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.transactions.rollback package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with rollback.

How to do it...

You can use the rollback DSL statement to throw an exception with an optional message.

In the XML DSL, we use the following code:

<from uri="direct:transacted"/> <transacted/> <setHeader headerName="message"> <simple>${body}</simple> ...

Get Apache Camel Developer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.