INFO: Ordering of Transacted Reads and Writes

ID: Q173327

The information in this article applies to:

SUMMARY

When messages are sent from the same machine, all of the messages associated with a given transaction are grouped together when read; and that group of messages arrives in the order that the messages are committed. The following pseudo code scenario shows the ordering of the messages:

   begin trans1
   begin trans2
      write trans1.msg1
      write trans2.msg1
      write trans1.msg2
      write trans2.msg2
   commit trans2
   commit trans1

This results in the following ordering of messages when read from the queue:

   trans2.msg1, trans2.msg2, trans1.msg1, trans1.msg2

However, this ordering may be different in some cases, as described below.

MORE INFORMATION

The above message ordering is correct as long as all the messages are sent from the same machine.

Consider the following case:

   Machine A
   begin transactiona
      send a1 to q
      send a2 to q
      send a3 to q
   commit transactiona

   Machine B
   begin transactionb
      send b1 to q
      send b2 to q
      send b3 to q
   commit transactionb

Microsoft Message Queue Server guarantees that all messages from A are ordered and all messages from B are ordered in the queue. But messages from A and B could be interleaved in the queue. For example, the queue could look like this:

   q: a1 b1 b2 a2 b3 a3

Microsoft Message Queue Server guarantees the following: For example, if you sent three messages with five minutes time to live in a transaction, and commit, MSMQ will begin sending those messages one by one. Because of their time to live, message 1 and 2 might get into the queue, and message 3 may not because it will expire. Every message is autonomous, even if they were sent in the same transaction.

A message will be put into a queue, whenever it reaches the target queue manager. MSMQ does not wait for all the messages sent in the same transaction to reach the queue manager, before putting them all in the queue.

To determine when all messages written in a transaction have been read, an application has to tag all the messages sent in the same transaction, and define whenever the last message is sent/received.

REFERENCES

MSMQ SDK Online help

Keywords          : MQGen kbfaq
Version           : WinNT:1.0
Platform          : winnt

Last Reviewed: January 30, 1998