NGWS objects written in a managed language, such as Microsoft Visual Basic 7.0, can send and receives messages from a MSMQ queue.
MSMQ is a technology that implements message queuing in an application. With MSMQ, you can create or delete message queues; send or receive messages; and manage message queues.
Transactions are an important part of enterprise systems, which frequently require the asynchronous capabilities of MSMQ. The NGWS runtime supports manual transactions through MSMQ class libraries for both internal and external transactions.
Internal transactions are simple, optimized for performance, and limited in scope. These transactions are called internal because they are handled entirely inside the MSMQ and are unsupported by the Distributed Transaction Coordinator (DTC) or any other transactional mechanism. DTC is Microsoft's transaction monitor.
Internal transactions have a very simple programming model. The following code fragment shows two messages composed in a single transaction. MSMQ ensures the delivery of both messages, or the transaction fails and neither message is delivered.
try { mq.BeginTransaction(); messageA = mq.Receive(1000); messageB = mq.Receive(1000); mq.CommitTransaction(); } catch(Exception e) { mq.RollbackTransaction(); }
Although simple to program, internal MSMQ transactions exclude database operations. Thus, if your application requires multiple operations, such as receiving a message from a message queue and putting the message in a database, and you want to execute these operations in the scope of one transaction, you will have to use an external transaction.
The NGWS runtime provides the following class, which gives MSMQ access to distributed transactions served up by DTC:
namespace System.Messaging { public class MessageQueue { //. . . public void BeginTransaction(); public void CommitTransaction(); public void RollbackTransaction(); //. . . } }
An external transaction through the MessageQueue class is manual because you explicitly begin the transaction, commit or roll back the operation, and manually enlist each resource manager through DTC.
The following table lists and describes the methods exposed by the MessageQueue class.
Method | Description |
---|---|
BeginTransaction | Creates a new Microsoft Message Queue Server (MSMQ) internal transaction. |
CommitTransaction | Commits a pending internal transaction. |
RollbackTransaction | Rolls back the pending internal transaction. |