We have what I believe is a fairly common XA use case:
- Read a message from an in-queue
- write some data to a database
- write a response message to an out-queue (which is different from the in-queue)
However we also need a way to handle internal errors and poison messages. The control flow we have in mind is something like this:
- read the message from the in-queue
- write to the database
- if there's an exception roll back the database transaction
- if there's no exception run commit phase1 on the database
- if everything went fine (no rollback and commit phase1 ok) write a success message to the out-queue
- if either commit phase1 on the database failed or there was an exception and the database transaction was rolled back write a failure message to the out-queue
- commit the in-queue, out-queue and database (unless rolled by because of an exception)
Is this a good approach, should we do it differently? How can we do this with EJBs?