NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Sending Messages Within an Internal Transaction

Internal transactions involve only Message Queuing resources and are managed entirely from within Message Queuing. You use the following language elements to indicate an internal transaction:

Element Used to
BeginTransaction Indicate the start of a transaction that consists of one or more messages and operations
CommitTransaction Used to commit the transaction if all of the message operations it contained were performed successfully
RollbackTransaction Used to undo all of the previously performed messaging operations if one of the operations in the transaction cannot be completed successfully.
Note A disconnected or full queue is not considered a failure. You decide in your code for the RollbackTransaction method what constitutes a rollback.

To send messages within an internal transaction

  1. Create an instance of the MessageQueue component and set its Path property to the queue to which you want to refer. For details, see Creating MessageQueue Components.
  2. Call the BeginTransaction method on the component.
  3. Define each message you want to send after calling BeginTransaction. For details, see Creating MessageQueue Components.
  4. After the last message you want to send in the transaction, call CommitTransaction.
  5. Enclose the entire transaction in Try/Catch error-checking code to handle any errors that arise. If you detect an error, roll back the transaction by calling the RollbackTransaction method.
Your code might look like this:
[Visual Basic]
Try
  mq.BeginTransaction  
  messageA = mq.Send(1000)
  messageB = mq.Send(1000)
  mq.CommitTransaction
Catch
  mq.RollbackTransaction
End Try 
[C#]
try {
  mq.BeginTransaction();  
  messageA = mq.Send(1000);
  messageB = mq.Send(1000);
  mq.CommitTransaction();
}
catch {
  mq.RollbackTransaction();
}

See Also

Transactional Message Processing | Creating a Transactional Queue | Creating MessageQueue Components | Sending and Serializing Messages