0
votes

I have created a transactional que in MSMQ. Then I successfully submit two messages to that queue. The first message will cause an error in the processor and the MSMQ transaction will roll back; hence the message will get put back in the queue. The second message will succeed when processed and MSMQ transaction will commit.

Note: I do not have code to move the first message to another/poison queue yet which means it will keep getting picked up for processing and theoretically message 2 will never get a chance to be processed.

Problem: If I have 1 listener/processor processing message from that transactional queue, message 2 will never get picked up. This is expected.

However, If I have two listeners, message # 2 does get picked up; which confuses me. I thought MSMQ transaction queue will only let messages be processed in the order they arrived.

On a Side Note: How do I decide that the message 1 cannot be processed further and move it to the another queue. Does MSMQ keeps count of how many times a message was picked up by the processor?

1

1 Answers

0
votes

A message exists in the queue until it has been read. When your 1st listener reads the poison message, it is marked as hidden until the transaction aborts and the message becomes visible again. During that time, the 2nd listener cannot see the poison message and will only see the 2nd message.

"How do I decide that the message 1 cannot be processed further and move it to the another queue." - WCF/MSMQ has poison message handling built in. You could simulate that yourself with a number of retry queues. On first failure, always move to retry queue #1; try the message again and, on failure, always move to retry queue #2; try the message again and, on failure, move to final queue for investigation.

"Does MSMQ keeps count of how many times a message was picked up by the processor?" - No.