We have what we 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, the out-queue and the 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?
We're using EJB 3.1 on JBoss AS 7.2 / EAP 6.1, coding against Narayana directly is an option. The JDBC driver is ojdbc7-12.1.0.1 and the JMS RAR is MQ Series (don't know the version).