Database transactions is a familiar concept.
try {
...
..
updateDB()
..
...
commit();
} catch error {
rollback();
}
if any error occurs any changes made by updateDB will be discarded.
I wanted to know what a message queue transaction rollback will undo.
try{
...
...
//EDIT: swapped the order of receive and send
Message m = queue1.receiveMessage(..)
..
..
queue2.sendMessage(..)
..
..
commit();
} catch error {
rollback();
}
specifically, what will rollback do
or am i stretching the database tx analogy too far.
thanks
EDIT: i am not implying the send and receive operations are related. i just wanted to say there are two operations that change the state of the message broker -- receive will take out a message from the queue which will be unavailable for other consumers if there were any.
The JMS API Session interface provides commit and rollback methods that you can use in a JMS client. A transaction commit means that all produced messages are sent and all consumed messages are acknowledged.
The Java Message Service (JMS) makes it easy to develop enterprise applications that asynchronously send and receive business data and events. It defines a common enterprise messaging API that is designed to be easily and efficiently supported by a wide range of enterprise messaging products.
JMS applications can run local transactions by first creating a transacted session. An application can commit or roll back a transaction.
To make a session transactional set transacted=true flag on the JMS endpoint and configure a transactionManager on the Component or Endpoint.
Rollback of the send is straight forward, the message will not be put to queue2.
Rollback of the receive will typically put the message back on the queue (queue1). Depending on your JMS provider setup and configuration, the message will be redelivered a number of times. If the transaction rolls back too many times (too many is configurable) it will be put to a "Backout queue" (or dead letter queue), so that it will not block the queue for other messages. A backed out message typically needs some manual error handling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With