I'm working on a service where I listen to the queue, deserialize received messages, and persist them to a database (Oracle). Roughly:
@JmsListener(destination="some-destination")
public void onMessage(Message message) throws Exception {
String message = ((TextMessage) message).getText();
service.save(deserialize(message));
// includes exception handling etc
}
In the default message listener bean I set the concurrency and setSessionTransacted(true)
. Is this enough to make the whole onMessage transactional? So that a message is received and saved in one transaction, and rolled back if there's a failure at any of these points?
I tried throwing exceptions on specific messages when there was an attempt to save them - and the messages were indeed rolled back to the queue and the listener tried to consume them again, which is a desired behavior.
When researching this, I stumbled upon distributed transactions, jta transaction manager, but I am still not sure whether more needs to be configured apart from setSessionTransacted(true) or whether Spring Boot automatically handles transactions of XA resources.
Looking for advice. Thank you.