INFO: Using a Single MSMQ Queue for an MTS Component

Last reviewed: March 6, 1998
Article ID: Q174387
The information in this article applies to:
  • Microsoft Message Queue Server version 1.0
  • Microsoft Transaction Server 1.0

SUMMARY

Microsoft Message Queue Server (MSMQ) send and receive operations can be included in Microsoft Transaction Server (MTS) transactions. Since an MTS component can be marked for transactions in several ways, you may need to manage two types of queues and write conditional code to avoid queue and component type mismatch (MQ_ERROR_TRANSACTION_USAGE error). It is possible to use a single transactional queue in all the cases. MTS provides the context object, IsInTransaction() method, to determine whether or not the component is transactional. MSMQ provides specific flags in send and receive APIs and ActiveX calls to deal with specific cases.

MORE INFORMATION

The following table shows the results of using MQ_MTS_TRANSACTION constant in the pTransaction parameter of send/receive APIs and ActiveX methods for different combinations of components and queue types.

   T= Transactional , N= Non-transactional

   MQ_MTS_TRANSACTION in MQSendMessage/ Send:

   Component    Queue        Result
   --------    ---------   ---------
   T               T         OK
   T               N         Error
   N               N         OK
   N               T         Error


   MQ_MTS_TRANSACTION in MQReceiveMessage/ Receive:

   Component      Queue      Result
   ---------   ---------    ---------
   T               T         OK
   T               N         Error
   N               N         OK
   N               T         OK, *

   *(assume local queue)

How to Use a Single Transactional Queue with MQSendMessage/Send

If the component is non-transactional, use the MQ_SINGLE_MESSAGE constant in the pTransaction parameter of MQSendMessage/Send call to send to a transactional queue. This makes the message transactional. This is an independent transaction not related to the MTS transaction and will not rollback the send operation if the MTS component is marked transactional and you call SetAbort to abort the MTS transaction.

How to Use a Single Transactional Queue with MQReceiveMessage/Receive

Use MQ_NO_TRANSACTION constant in the pTransaction parameter of MQReceiveMessage/Receive call. This makes it possible to receive non- transactionally from the transactional queue even if the queue is not local.

You will need to use the MTS context object, IsInTransaction() method, to determine whether or not the component is transactional and then pass the appropriate flag to the MSMQ send/receive call. For code example using MSMQ C API and ActiveX see the following articles:

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q175725
   TITLE     : HOWTO: Using MSMQ C API Inside an MTS Component

   ARTICLE-ID: Q175726
   TITLE     : HOWTO: Using MSMQ Within an MTS Component in Visual Basic

   ARTICLE-ID: Q176816
   TITLE     : HOWTO: Using MSMQ within an MTS Component in Java


Additional query words: viper falcon
Keywords : MQProg
Version : WINNT:1.0
Platform : winnt
Issue type : kbinfo


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: March 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.