It's not clear from Spring AMQP documentation on transactions if it's possible to do everything in one transaction: listen to RabbitMQ, receive a message from queue 1, do processing (including persistence) and publish message to queue 2. And if any of these steps fails, all operations in the transaction roll back (including database transaction rollback, rollback on publishing to queue 2 and rollback on receiving from queue 1 - requeuing). Can this work and how can it be implemented in code? For example, we make listener from queue 1 transactional and do data processing and publishing to queue 2 from this listener?

Can this transaction provide exactly once delivery guarantee?

1

There are 1 answers

2
Gary Russell On BEST ANSWER

See https://docs.spring.io/spring-amqp/docs/current/reference/html/#transactions

As long as the listener container and template are transactional, the work will be performed in one transaction.

You can also synchronize a database transaction with it; however, it is not atomic (XA), it is "Best effort 1PC". See https://www.infoworld.com/article/2077963/distributed-transactions-in-spring--with-and-without-xa.html

No; exactly once is not possible, it is at least once; you will have to deal with possible duplicates.