0
votes

I'm trying to understand the concept of transaction messaging on MSMQ as well as transaction support in wcf.

For Queues with transaction support, does it mean the following set of operations will be automatic?

  1. Client A on Machine 1 writes a row in its application database that message sent to queue.
  2. Creates/Sends a Order Create message to a queue (say MSMQ).
  3. The MSMQ message gets picked up by Client B on Machine 2.
  4. Client B creates an Order Row in its own application Database?

If I do all the above step in a distributed transaction, does it mean all 4 steps will either fail or succeed atomically?

Or transaction will only apply from step 1 - 2?

Similarly, if say WCF was involved above instead of the MSMQ, will all steps be atomic i.e within a transaction?

1
All steps within the distributed transaction will either commit or roll back.John Breakwell

1 Answers

1
votes

Short answer: 1+2 is a transaction, then 3+4 is a second transaction.

The only way that 3 might conceivably be in the same transaction as 2 would be for the receiver to be in the same transaction context as the sender (i.e., the same logical thread of execution). Otherwise, as the first transaction has not been committed, the message would not yet be visible for receiving. To propagate the transaction context from the sender to the receiver, there would have to be a second communication channel from the sender to the receiver (i.e., a remote invocation), which would render the message queue redundant. But this doesn't really make sense, as receiving might even get a different message from the queue...

In fact, the point of transactional MQs is precisely to decouple the sender and the receiver in two different transactions, such that the sender is not impacted by the availability and performance of the receiver, at the expense of isolation. The MQ thus provides store and forward atomicity+durability without having two different applications (1 and 4) within the same transactional context. You'll have 1+2 atomically, and eventually 3+4 atomically.

With WCF you can have 1 and 4 in the same transaction, by using WS-AtomicTransactions instead of MQ. In comparison to the MQ solution, this also gives you isolation, as you never observe the effects of 1 without the effects of 4.