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!

MessageQueue.Transactional

Gets a value indicating whether the queue supports transactions.

[Visual Basic]
Overridable Public ReadOnly Property Transactional As Boolean
[C#]
public bool Transactional {virtual get;}
[C++]
public: __property virtual bool get_Transactional();
[JScript]
public function get Transactional() : Boolean;

Property Value

true if the queue can only accept messages that are sent as part of a transaction; otherwise, false.

Exceptions

Exception Type Condition
MessageQueueException The attempt to get the Transactional setting generated an internal error on the message queue component. The error is specified by the given status message.

Remarks

Transactional messaging implies the coupling of several related messages into a single transaction, ensuring that the messages are delivered in order, delivered only once, and are successfully retrieved from their destination queue.

If a queue is transactional, it can only accept messages that are sent as part of a transaction. However, messages can be retrieved from a local transaction queue without using a transaction. If a non-transactional message comes to a transactional queue, a transactional context is created for the message.

Example [Visual Basic]

The following is pseudocode.

The following example checks to see if a Message Queuing transactional backend resource exists. If is does, and supports transactions, it connects to the queue. Otherwise, it creates a new transactional backend resource with the path passed in, for example "myComputer\myQueue". It then creates a transaction, which sends messages to the billing and shipping queues.

If the process fails, the transaction is rolled back. Otherwise, it is committed. In the case of success, a message is sent to the new transactional queue and a message box provides notification of the event. This subroutine assumes that the queue path that you will create or use has been specified and passed in as the transQueuePath.

[Visual Basic]

Private Sub CreateNewTransactionalQueue(ByVal transQueuePath As String, ByVal order As Variant)
    'Create a new MessageQueue object
    Dim mq As System.Messaging.MessageQueue.MessageQueue
    Dim billingQueue As System.Messaging.MessageQueue.MessageQueue
    Dim shippingQueue As System.Messaging.MessageQueue.MessageQueue
    'Set the paths for the billing and shipping queues to existing queues
    'note that we are not creating new backend resources, just connections
    Set billingQueue = New System.messaging.MessageQueue.MessageQueue("myComputer\billing")
    Set shippingQueue = New System.messaging.MessageQueue.MessageQueue("myComputer\shipping")
    'If a queue at the specified path does not exist, create one
    If Not MessageQueue.Exists(transQueuePath) Then
        Set mq = MessageQueue.Create(transQueuePath, True)
    Else
        'Else, point to the existing queue
        Set mq = New MessageQueue(transQueuePath)
        'verify that the queue backend resource supports transactions
        If Not mq.Transactional Then
'The queue exists but is not transactional. 
'Send notification and return.
MessageBox.Show "Queue " & transQueuePath & " already exists."
Return
        End If
    End If
    Try
        'begin a transaction
        mq.BeginTransaction
        'send order information to the billing and shipping queues
        billingQueue.Send order
        shippingQueue.Send order
        'commit the transaction (messages have been successfully sent 
        'to shipping and billing)
        mq.CommitTransaction
        'Send a message to the transactional queue
        mq.Send "Test message sent to queue."
        'Send notification that a message has been sent to the queue.
        messagebox.Show "Message sent to " & mq.QueueName & "."
    Catch
        'there has been an error. Rollback the transaction
        mq.RollbackTransaction
        'Send notification that the transaction was rolled back
        messagebox.Show "Transaction rolled back."
    End Try
End Sub

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | BeginTransaction | CommitTransaction | RollbackTransaction