What happens if a message is rolled back in MQ?

Manglu picture Manglu · May 26, 2009 · Viewed 13.7k times · Source

I receive a message from a WebSPhere MQ queue. I try to process and if i receive some exceptions i want to rollback the message to the MQ Queue.

I have no problems in doing the same. What happens to the message? Does it go to the bottom of the queue?

If i try and pull a message from the queue would i receive the same message that i rolledback?

What is the behaviour likely to be? I want to know this behaviour typically in a high volume Queue scenario?

Appreciate any inputs.

Thanks, Manglu

Answer

Cheeso picture Cheeso · May 26, 2009

If you are doing queue operations within the scope of a transaction, and a rollback occurs, then after the transaction resolves the queue and message will appear just as it did before the transaction began. In other words no changes at all.

In a high volume scenario, though, it is typical to have multiple transactional readers and writers on a single queue, and they do not lock the entire queue for each de-queue or enqueue.

These readers and writers will insert items into the queue, or dequeue items from the queue transactionally, while your doomed transaction is resolving. In that case, other queue items may appear or disappear (or both).

If after rollback of the original transaction, you again dequeue from the queue, you may get the original message, but you may not. In a high-volume, high-concurrency scenario, it is possible that another reader will have pulled the message before your code can do so.