How to set up a message queue?
1.Windows-->Control Panel--> Computer Management --> Services and Applications --> Message Queuing--> Private Queues
If you do not see Message Queuing you may need to install this windows features from the add and remove programs.
2. Create a Main Queue and a Acknowledgement Queue.
3. Copy the path and use them in the code below. It is ideal to store them as config elements and use the value.
Example of the path " localhost\private$\MainQueue "
Dim MainQueue As New System.Messaging.MessageQueue()
Dim AcknowledgementQueue As New System.Messaging.MessageQueue()
Dim Message As New System.Messaging.Message()
Dim AcknowledgementMessage As New System.Messaging.Message()
MainQueue.Path = "MAIN QUEUE PATH"
AcknowledgementQueue.Path = "ACKNOWLEDGEMENT QUEUE PATH"
Message.Body = "TEST MESSAGE"
Message.Formatter = New BinaryMessageFormatter(FormatterAssemblyStyle.Simple, FormatterTypeStyle.TypesAlways)
Message.Recoverable = True
'Commented to avoid sending the messages to the deadletterqueue
'Message.UseDeadLetterQueue = True
Message.ResponseQueue = oInterfacesSubmitAckQueue
Message.Label = _Payload.GetType().FullName
Message.Priority = Messaging.MessagePriority.Normal
Message.Formatter = New BinaryMessageFormatter(FormatterAssemblyStyle.Simple, FormatterTypeStyle.TypesAlways)
Message.AcknowledgeType = AcknowledgeTypes.NotAcknowledgeReachQueue Or AcknowledgeTypes.FullReachQueue
Message.AdministrationQueue = AcknowledgementQueue
MainQueue.Send(theMessage)
MainQueue.Close()
AcknowledgementMessage = MainQueue.Receive(New TimeSpan(0, 0, 2))
If AcknowledgementMessage.Acknowledgment <> Acknowledgment.ReachQueue Then
' Code to perform actions when the message did not reach the message queue
Else
End If
No comments:
Post a Comment