XA or non-XA for JMS and DB operation

user726579 picture user726579 · Jan 17, 2014 · Viewed 7.7k times · Source

I am fairly new to the XA and non-XA world. My requirement is to read a message from queue until there is a NO message. For each message in the queue, go to DB and do some transactions like select, insert, update.

Is this possible to achieve this using non-XA datasource? I am currently using XA datasource but learned that it is costly and performance hit.

Appreciate any help! Thanks

Answer

trikelef picture trikelef · Jan 17, 2014

If you need to include in your transaction both interaction with a JMS connection (i.e. send or receive a message) and connecting with a database, by using a db connection then you definitely need an XA-datasource since your transaction is a two-phase commit (2PC) transaction.

In a two-phase commit transaction you either commit the changes to all your resources (in your case JMS and DB resources) or rollback all changes if something goes wrong with either of them.

To do this you need to connect to an XA-enabled datasource. Additionally, in a Java EE container, JMS Connections should already be XA-Enabled.