Because of how the MSMQ API has been designed, i.e. polling receive that throws an exception when MSMQ timeout is reached, the receive algorithm is more complex than other polling-driven transports (such as SQLServer).
The main loop starts by subscribing to the
PeekCompleted event and calling the
BeginPeek method. When a message arrives, the event is raised by the MSMQ client API. The handler for this event starts a new receiving task and waits until this new task has completed its
Receive call, after which it calls
BeginPeek again to wait for more messages.
MSMQ Transport supports the following Transport Transaction Modes:
- Transaction scope (Distributed transaction)
- Transport transaction - Send atomic with receive
- Transport transaction - Receive only
- Unreliable (Transactions disabled)
See also Controlling Transaction Scope Options.
In this mode, the ambient transaction is started before receiving the message. The transaction encompasses all stages of processing including user data access and saga data access.
MSMQ does not support Snapshot isolation level. Snapshot isolation level is suitable only when persistence is required. This isolation level can be applied only on the persister if the transport and persistence do not share the same transaction. Lower the transport transaction mode to at least Sends atomic with receive, use WrapHandlersInATransactionScope, and pass
IsolationLevel. as a parameter. This has consistency issues as mentioned in the Transport Transactions Consistency Guarantees article
In this mode, when a message is received, it is immediately removed from the input queue. If processing fails, the message is lost because the operation cannot be rolled back. Any other operation that is performed when processing the message is executed without a transaction and cannot be rolled back. This can lead to undesired side effects when message processing fails part way through.