Gets or sets the message priority.
[Visual Basic] Public Property Priority As MessagePriority [C#] public MessagePriority Priority {get; set;} [C++] public: __property MessagePriority get_Priority(); public: __property void set_Priority(MessagePriority); [JScript] public function get Priority() : MessagePriority; public function set Priority(MessagePriority);
One of the MessagePriority enumeration values. This value represents the priority level of a nontransactional message. The default is Normal.
Priority provides access to the Priority property of the Message Queuing application's MSMQMessage object.
Priority can only be set for non-transactional messages, since the Priority for transactional messages is automatically set to 0. Priority is ignored by the transaction.
Message priority affects how Message Queuing handles the message while it is in route, as well as where the message is placed in the queue. Higher priority messages are given preference during routing and inserted toward the front of the queue. Messages with the same priority are placed in the queue according to their arrival time.
The following example demonstrates defining different DefaultPropertiesToSend based on whether a message passed into the procedure has highest or normal MessagePriority. The properties that are set, which apply to the message to be sent to the message queue, are the Label, the Priority, the TimeToBeReceived, and the TimeToReachQueue. It is important to note that these properties are set through the MessageQueue, but they apply to the Message object.
This example assumes that the calling procedure passes in a MessagePriority, and that an urgent message is indicated by Highest priority. It also assumes that the calling method defines the Message that is to be sent to the queue.
[Visual Basic]
Private Sub SetDefaultPropertiesToSend(ByVal urgency As MessagePriority, ByVal msg As System.Messaging.Message) 'Create DefaultPropertiesToSend objects Dim urgentMessageProperties As DefaultPropertiesToSend Dim normalMessageProperties As DefaultPropertiesToSend 'Define and instantiate a new MessageQueue object Dim MessageQueue1 As System.Messaging.MessageQueue.MessageQueue Set Me.MessageQueue1 = New System.Messaging.MessageQueue 'Set the queue formatter to the XML-based formatter Set MessageQueue1.Formatter = New System.Messaging.XmlQueueMessageFormatter Set MessageQueue1.DefaultPropertiesToSend.UseDeadLetterQueue = True 'Set the label for the queue (as opposed to the message labels). Set MessageQueue1.Label = "Order Queue" 'Set the queue path MessageQueue1.Path = "mycomputer\myqueue" 'Instantiate two new DefaultPropertiesToSend objects Set urgentMessageProperties = New DefaultPropertiesToSend Set normalMessageProperties = New DefaultPropertiesToSend 'Set the label and priority for urgent messages urgentMessageProperties.Label = "Urgent Message" urgentMessageProperties.Priority = MessagePriority.Highest 'Make the process wait indefinitely for a message. urgentMessageProperties.TimeToBeReceived = Message.InfiniteTimeout urgentMessageProperties.TimeToReachQueue = Message.InfiniteTimeout urgentMessageProperties.UseDeadLetterQueue = True 'set the label and priority for normal messages normalMessageProperties.Label = "Normal Message" normalMessageProperties.Priority = MessagePriority.Normal 'Make the process wait a finite amount of time for a message. normalMessageProperties.TimeToBeReceived = 3000 normalMessageProperties.TimeToReachQueue = 3000 normalMessageProperties.UseDeadLetterQueue = True 'If the message is urgent, use the urgent DefaultPropertiesToSend If urgency = MessagePriority.Highest Then Set MessageQueue1.DefaultPropertiesToSend = urgentMessageProperties Else 'Otherwise, use normal DefaultPropertiesToSend Set MessageQueue1.DefaultPropertiesToSend = normalMessageProperties End If 'Override default properties on the message object msg.Priority = MessageQueue1.DefaultPropertiesToSend.Priority msg.Label = MessageQueue1.DefaultPropertiesToSend.Label msg.TimeToBeReceived = MessageQueue1.DefaultPropertiesToSend.TimeToBeReceived msg.TimeToReachQueue = MessageQueue1.DefaultPropertiesToSend.TimeToReachQueue 'Send the message that was passed in. MessageQueue1.Send msg 'Display Label and MessagePriority information on the screen MessageBox.Show MessageQueue1.DefaultPropertiesToSend.Label & ". Priority: " & MessageQueue1.DefaultPropertiesToSend.Priority End Sub
DefaultPropertiesToSend Class | DefaultPropertiesToSend Members | System.Messaging Namespace | TBD