Provides access to a Message Queuing backend queue resource.
[Visual Basic] Public Class MessageQueue Inherits Component [C#] public class MessageQueue : Component [C++] public __gc class MessageQueue : public Component [JScript] public class MessageQueue extends Component
The MessageQueue class provides a reference to the Message Queuing backend resource. You can connect to an existing resource by specifying its path in the MessageQueue constructor, or create a new backend resource. The instance created in your application must be connected to an existing queue before you can call Send, Peek, or Receive messages. Once connected to a backend resource, you can manipulate the queue properties, like Category and Label.
MessageQueue supports two types of message retrieval, asynchronous and synchronous. The synchronous methods, Peek and Receive, specify a timeout during which the process thread waits for a new message to peek or read. The asynchronous methods, BeginPeek and BeginReceive, allow main application tasks to continue until a message arrives in the queue. The asynchronous methods allow processing to continue in separate threads through the use of callback objects and state objects that communicate information across threads.
Instantiating a MessageQueue object does not result in the creation of a new backend resource, but you can use the Create, Delete, and Purge methods to manage queue resources on the server.
The MessageQueue object supports several ways in which the queue's Path property can be specified. You can use the friendly name defined by the queue's MachineName and QueueName. For public queues, this is MachineName\ QueueName, while for private queues this is MachineName\Private$\ QueueName. Alternately, the FormatName can be specified to support off-line access to message queues. Finally, the queue's Label property can be used to define the queue's Path.
Message Queuing technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues
When an instance of MessageQueue is created, some of the read/write properties are set to initial values. For a list of these values, see the #ctor constructor.
Namespace: System.Messaging
Assembly: system.messaging.dll
The following example creates a new MessageQueue object and sends a message to the queue.
This example assumes that there is a priority specified to be 'very low', 'normal', or 'very high' and a body (say, a text string) passed into the procedure. It also assumes there is a Message Queuing computer named myComputer and a queue on that computer called myQueue.
Import the System.Messaging namespace for this example.
[Visual Basic]
Private Sub SendPriorityMessage(ByVal priority As String, ByVal body As Object) 'Create a new MessageQueue object. Dim mq As MessageQueue 'Initialize the MessageQueue object using the constructor. mq = New MessageQueue 'Set the queue path to an existing queue. mq.Path = "myComputer\myQueue" 'Determine the priority from the value passed in. Select Case priority Case "very high" mq.DefaultPropertiesToSend.Priority = MessagePriority.VeryHigh Case "very low" mq.DefaultPropertiesToSend.Priority = MessagePriority.VeryLow Case "normal" mq.DefaultPropertiesToSend.Priority = MessagePriority.Normal End Select 'Send a message to the queue. mq.Send(body) End Sub
MessageQueue Members | System.Messaging Namespace | Message | DefaultPropertiesToSend | MessageQueueException | MessageQueue | Send | Peek | Receive | BeginPeek | BeginReceive | Path | Label | FormatName | QueueName | MachineName | Create