Question

Currently I have a spring JMS listener which listens on to an EMS topic and on getting a message processes it and persists it. However, I would like to do all this under one transaction. I am aware this requires XA since there are two global resources which have to register with the Transaction Manager. This can be achieved via JTA that spring provides. However, since my application is standalone, do I require to include a third party JTA standalone implementation like Bitronix or JOTM. I ask this because since both are spring resources, the default JTA should handle this.

Was it helpful?

Solution

Yes you will need to include a third-party TransactionManager implementation that supports XA.

Most application servers e.g. JBoss will bundle an XA TransactionManager of their choice. This is one of the reasons to choose an ApplicationServer over something like Tomcat or a standalone application; the configuration of things like XA transactions is basically done for you.

Sometimes an ApplicationServer is too heavyweight (although I think this is becoming less of a problem) or you can't use one. In this scenario it is your responsibility to provide the TransactionManager implementation if you want to use XA.

You can take your pick from implementations such as: JBossTS, Atomikos Transaction Essentials or Bitronix JTA.

Spring does include a JTATransactionManager implementation. This will either use pre-configured locations to detect the selected XA implementation if you're running in an ApplicationServer, or alternatively you need to configure it yourself if you're in a standalone environment.

There are some excellent resources on configuring an XA TransactionManager with Spring:

  1. http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
  2. http://www.javaworld.com/article/2077714/java-web-development/xa-transactions-using-spring.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top