Using database transactions with Apache Camel

Just put an example of using database transactions with Apache Camel on github:

It is based on the example given at the start of Chapter 12 of “Camel In Action”, but using database transactions, rather than a JMS transaction. It has two routebuilders:

  • TransactionlessJDBCRouteBuilder
  • TransactedJDBCRouteBuilder

There are four testcases:

  1. TransactionlessJDBCTest.transactionlessJDBCTest_noError – will succeed, and shows that transactionless routebuilder inserts two records if there are no exceptions.
  2. TransactionlessJDBCTest.transactionlessJDBCTest_withConnectionProblem – will fail, showing that when the second insert fails, the first one is not rolled back.
  3. TransactedJDBCTest.transactedJDBCTest_noError – will succeed, showing two records inserted.
  4. TransactedJDBCTest.transactedJDBCTest_withConnectionProblem – will succeed, showing that the first insert is rolled back if the second one fails.

The project is built with Maven, so to run it, you need Maven on your path, and then you can run:

mvn test

Of course you can run the tests individually if you want by using the -Dtest parameter with maven. e.g.

mvn test -Dtest=TransactionlessJDBCTest

This entry was posted in Camel, Databases and SQL and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags are not allowed.

515,238 Spambots Blocked by Simple Comments