Sending Messages Using an Internal Transaction

To send a message within an internal transaction, the MSMQTransactionDispenser is used to create the transaction object. After the transaction object is created, make sure it is referenced in the call to Send.

Note  Each MSMQ message can have no more than 4 MB of data.

    To send a message using an internal transaction
  1. Specify the type of transaction dispenser you want to use. For internal transactions, specify the MSMQTransactionDispenser object.
    Dim xdispenser as New MSMQTransactionDispenser
     
  2. Call BeginTransaction.
    Set xact = xdispenser.BeginTransaction
     
  3. Open the queue with send access.
    Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
     
  4. Create and send the message. Make sure the call to Send is associated with the transaction.
    msg.Label = "MyTransaction message"
    msg.Body = "Message 1 Body"
    msg.Send qSend, xact                    'Associates send with xact.
    

Example

This example sends a single message within an internal transaction.

Dim xdispenser as New MSMQTransactionDispenser
Dim xact as MSMQTransaction

Dim qSend as MSMQQueue                
Dim msg as New MSMQMessage

Set xact = xdispenser.BeginTransaction

'Assumes queue already exists and is transactional.
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
msg.Label = "MyTransaction message"
msg.Body = "Message 1 Body"
msg.Send qSend, xact                     'Associates send with xact.