INFO: Ordering of Transacted Reads and Writes

Last reviewed: January 28, 1998
Article ID: Q173327
The information in this article applies to:
  • Microsoft Message Queue Server version 1.0

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:
  • On the sender machine, if you send multiple messages inside a transaction at commit time, the messages will all be sent (NOTE: the messages will be sent, but not necessarily received), or at abort time none will be sent.
  • MSMQ delivers the messages no more than once in the destination queue, and in order.

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


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 28, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.