Michał Kowalczyk
Michał Kowalczyk

Reputation: 478

Do I need an XA Transaction? DefaultMessageListenerContainer local transaction vs XA Connection Factory

In my Spring Boot application I have a following scenario:

  1. Read message from JMS queue
  2. Do some things with the data.
  3. Do a JDBC insert to Oracle database

If at any stage an exception occurs, I would like to be sure that the message isn't lost and is placed in the Backout Queue.

Do I need an XA transaction between XA-enabled JMS connection factory and XA-enabled Oracle db driver? Or is it sufficient to use for example DefaultMessageListenerContainer with sessionTransacted flag set to true?

And if the second one is the right answer, what would be a good situation to use XA transaction?

Upvotes: 0

Views: 920

Answers (1)

Gary Russell
Gary Russell

Reputation: 174574

You can avoid XA by using Spring to synchronize the two transactions and coding your app to handle the (small) possibility of a duplicate delivery (when the DB commits but the JMS rolls back due to, say, a lost connection between the DB and JMS commit). I suggest you read the excellent Distributed transactions in Spring, with and without XA by Dave Syer from the Spring team.

If javaworld moves that link sometime in future, google syer xa spring and you should find it.

Upvotes: 2

Related Questions