I want to find a way to apply a custom interceptor with JTA @Transactional
annotation.
I have a method with @Transactional
which is one of business-transactions. In that method I want to:
If any of the two fails both of them should not be done (i.e. they should be rolled back).
Currently I use Google Cloud pubsub as the messaging service, but this library does not seem to be compatible with JMS or JTA. Therefore, I'm wondering if I can implement a custom interceptor for that library (e.g. queue messages during a transaction, and publish the queued messages when the transaction is successfully committed).
Is there any good idea to do that?
Framework is Quarkus, and the JTA implementation is Narayana for now.
No. JTA @Transactional requires your messaging platform to have a transaction manager that ideally support the XA API or at least some form of transactional semantics: begin(), commit() and rollback() - begin() might not be necessary, but definitely rollback() is.
If something goes wrong with the second message inside your transaction, you want to make sure that the first message 'disappears' as if it never happened and rollback the complete transaction.
But, as of now, Google pub/sub has no notion of transaction, transaction IDs or commit() and rollback().