Imports System
Imports System.Messaging
Public Class MyNewQueue
Public Shared Sub Main()
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
If myQueue.Transactional = True Then
Dim myTransaction1 As New MessageQueueTransaction
myTransaction1.Begin()
myQueue.Send("My Message Data.", myTransaction1)
myTransaction1.Commit()
End If
myQueue.Formatter = New XmlMessageFormatter(New Type() {GetType([String])})
Dim myTransaction As New MessageQueueTransaction
Try
myTransaction.Begin()
Dim myMessage As Message = myQueue.Receive(New TimeSpan(0, 0, 5), myTransaction)
Dim myOrder As [String] = CType(myMessage.Body, [String])
Console.WriteLine(myOrder)
myTransaction.Commit()
Catch e As MessageQueueException
If e.MessageQueueErrorCode = MessageQueueErrorCode.TransactionUsage Then
Console.WriteLine("Queue is not transactional.")
Else
If e.MessageQueueErrorCode = MessageQueueErrorCode.IOTimeout Then
Console.WriteLine("No message in queue.")
End If
End If
myTransaction.Abort()
End Try
Return
End Sub
End Class
|