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
- cancel the sending of message
- un-receive the message ie put back the received
message back to queue
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.
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.
Yes, you are stretching it too far.
In transacted mode, your queue.receiveMessage()
will never return (assuming that it is set to wait for a particular reply message, and not just "any" message), simply because queue.sendMessage()
didn't really send the message yet (it will be sent when the transaction is committed).
It's a common mistake, by the way. When using JMS (which is an asynchronous protocol) for synchronous communications, it is natural to view the send/receive cycle as consisting of one transaction. That, however, isn't the case. Once you issue sendMessage()
in transacted mode, nothing really happens yet; the message will be sent only when the transaction is committed.