Transactions

MSMQ is a WCF transactional resource manager. When you create a queue (either programmatically or administratively), you can create the queue as a transactional queue. If the queue is transactional, then the queue is durable and messages persist to disk. More importantly, posting and removing messages from the queue will always be done under a transaction. If the code that tries to interact with the queue has an ambient transaction, the queue will silently join that transaction. If no ambient transaction is present, MSMQ will start a new transaction for that interaction. It is as if the queue is encased in a TransactionScope with TransactionScopeOption.Required. Once in a transaction, the queue will commit or roll back along with the accessing transaction. For example, if the accessing transaction posts a message to the queue and then aborts, the queue will reject the message.

Delivery and Playback

When a nontransactional client calls a queued service, client-side failures after the calls will not roll back posting the message to the queue, and the queued call will be dispatched to the service. However, a client calling a queued service may do so under a transaction, as shown in Figure 9-3.

Posting to a client-side queue

Figure 9-3. Posting to a client-side queue

The client calls are converted to a WCF message (or messages) and then packaged in an MSMQ message (or messages). If the client’s transaction ...

Get Programming WCF Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.