Spring Transaction Synchronization of JDBC and JMS Spring Transaction Synchronization of JDBC and JMS spring spring

Spring Transaction Synchronization of JDBC and JMS


This article might be of help Distributed transactions in Spring, with and without XA. I don't think it covers your case specifically - sending message + updating database.


Official Spring Boot repository contain JTA examples that combine JMS with JDBC based on Atomikos, Bitronix or Java EE server JBoss WildFly.

Additionally I also created few examples that are located in my Github repository. This contains also non-Spring Boot (pure Spring) example.


If you are using Local transactionsAnd the usecase is save to database and then send to jms

Then there could be three cases :

  1. Exception just after receiving(before DB and JMS)

No problem everything will be rolledback

  1. After saving to DB , we have exception

If there is an insert operation,there will be mutiple rows in DB due to retries.With each retry , an insert will be done.And for JMS , message will go to DeadLetterQueue

  1. After saving to DB and sending to JMS , we have an exception

    If there is an insert operation,there will be mutiple rows in DB due to retries.With each retry , an insert will be done.And for JMS , message will go to DeadLetterQueue

Now you dont want to use XA, so the solutions could be

1)Check If(message.getJmsRedelivered() {…}

If not , process it

If its redelivered , check if you processed it already

Check if the data is in database based on details in message

Note that re-deliveries are rare so , this check is also rare and there is no overhead

2)If your method is idempotent , then you dont need this check

And regarding XA , XA guarantees that message is delivered only onceAnd synchronize the transaction across multiple resources

But with XA , you have overhead

So if you can manage without XA , it is preferable