Share via


MSMQ COM+ Transactions

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

When your application is executing in the COM+ (Component Services) run-time environment, Message Queuing can send or receive messages within a COM+ transaction if the current COM+ object is participating in a transaction.

Message Queuing, COM+ (Component Services), and Microsoft® Distributed Transaction Coordinator (MS DTC) work together for this type of transaction.

COM+ transactions supersede the transactions implemented on computers running Microsoft® Windows NT® 4.0, Windows® 98, or Windows 95 by functions and methods provided by Microsoft® Transaction Server (MTS).

Note

For Microsoft Transaction Server topics in the Microsoft® Platform SDK, see Microsoft Transaction Server 2.0 Service Pack 1.

For more information about Microsoft Distributed Transaction Coordinator (MS DTC or DTC), see the Platform SDK.

As shown in the following illustration, Message Queuing links directly to the COM+ run-time environment, and, within the run-time environment, COM+ uses the services of MS DTC for creating the transaction object and for transaction coordination.

<No Change>

When a sending application calls MQSendMessage or MSMQMessage.Send with a request to send a message within a COM+ transaction, Message Queuing verifies that the application is running in the context of a COM+ transaction. If Message Queuing finds that no COM+ object is running or that the current COM+ object is not executing in a transaction, the message is sent as a nontransactional message. To avoid an attempt to send a nontransactional message to a transactional queue, which will fail, the sending application can use the IsInTransaction method provided by COM+ (Component Services) to verify that the current COM+ object is executing in a transaction before the message is sent. If the current context is not transactional, your application can explicitly or implicitly create its own transaction for the message.

Note

When writing applications for Microsoft Windows NT 4.0, Windows 98, or Windows 95, use the ObjectContext::IsInTransaction method provided by MTS.

When writing applications for Microsoft® Windows® 2000 or later, use the ObjectContext::IsInTransaction method provided by COM+ (Component Services).

The type of destination queue used has a decisive impact on the outcome. For example, in a nontransactional COM+ context, sending a message to a transactional queue will fail because a nontransactional message will be generated. However, in this situation, the message can still be sent to a transactional queue by using an independent single-message transaction.

When an application calls an API function or COM method with a request to receive or peek at a message within a COM+ transaction, Message Queuing verifies that the application is running in the context of a COM+ transaction. If Message Queuing finds that no COM+ object is running or that the current COM+ object is not executing in a transaction, the message is retrieved outside of a transaction. When retrieving messages, the receiving application can also use the IsInTransaction method to verify that the current COM+ object's context is transactional.

More Information

For information on See
Programming considerations for sending or receiving messages within a COM+ transaction COM+ Programming Design Considerations

Examples

For an example of See
Sending a message using a COM+ transaction C/C++ Code Example: Sending a Message Using a COM+ Transaction

 Visual Basic Code Example: Sending a Message Using a COM+ Transaction