Transactional persistence with MyBatis in ServiceMix

This post has been a long time coming. A while back I cooked up a sample application, kind of a pet store for integration, that demonstrates a bunch of things that you might want to do beyond the standard bootstrap examples. This app takes the form of a horoscope aggregator, which allows you to view the last x days worth of horoscopes for a starsign (perhaps for the purposes of checking how accurate, or not, they were). The project is available as usual on GitHub at FuseByExample/horo-app.

The app demonstrates a number of useful things that you would typically want to do in an integration:

  • MyBatis via Spring for persistence directly from Camel routes, as well as for use directly by a web app (seperate bundles)
  • database transactions via a Spring PlatformTransactionManager
  • testing of your MyBatis templates against an embedded database; the one I have used is H2, the one used by the real app is Postgres
  • templatize your Camel routes; the app consumes two seperate RSS feeds in exactly the same way, though with different endpoints
  • unit test your routes by dependency injecting your endpoints, and using the CamelTestSupport mechanisms
  • perform “semi-integration” tests via the @Rule annotation against an embedded server within your JUnit tests, in such a way that multiple integration tests can run at the same time on the same server. This plugs in to the integration test part of the Maven build lifecycle, via the maven-failsafe-plugin Incredibly useful for CI! In this case, the purpose was to test the behaviour of the camel-rss component as part of the route.
  • deploy CXF JAX-RS services alongside your Camel bundles to provide access to your data via XML and JSON using just the one mechanism
  • share expensive resources such as DataSources between bundles using metadata, such as the database name that they provide access to
  • idempotent consumption, so the same stuff doesn’t keep getting processed (saved to the database) over and over. This is saved to a JDBC IdempotentRepository in a live environment, and an in-memory one in tests.

Full documentation available in the README. Enjoy!


Posted

in

, , ,

by

Tags: