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, it is durable, and messages always persist to disk. More
importantly, posting messages to 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
constructed
with Transaction
Scope
Option.
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 call 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 call under a transaction, as shown in Figure 9-3.
Figure 9-3. Posting to a client-side queue
The client calls are converted to WCF messages and then packaged in an MSMQ message (or messages). If the client’s transaction ...
Get Programming WCF Services, 3rd Edition 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.