Priority
MSMQMessage

The Priority property specifies the message's priority. A low number indicates a low priority.

Type: Long
Run time: read/write

Syntax

object.Priority
 
Syntax Element Description
object Message (MSMQMessage) object that represents the message.

Settings

Set Priority to an integer value between 7 and 0 (the default is 3).

Remarks

Message priority affects how MSMQ 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.

MSMQ automatically sets the priority level of transactional messages to 0: Priority is ignored by the transaction. For information on transactions, see MSMQ Transactions.

If the message is sent to a public queue, a second priority (the queue's BasePriority property) is added to Priority for routing purposes. However, the queue's base priority has no effect on how messages are placed in the queue.

Example

This example first creates and opens a queue for sending messages, and then sets the priority level of two message and sends them off to the queue.

To try this example using Microsoft® Visual Basic® (version 5.0), paste the code into the Code window of a form, run the example, and click the form.

Dim qinfo As MSMQQueueInfo
Dim q As MSMQQueue
Dim msg1 As New MSMQMessage
Dim msg2 As New MSMQMessage

Private Sub Form_Click()
   '*************************
   ' Create queue (no error
   ' handling if queue exists.
   '**************************
  Set qinfo = New MSMQQueueInfo
  qinfo.PathName = ".\PriorityTest"
  qinfo.Label = "Test Queue"
  qinfo.Create
   '**************
   ' Open queue.
   '**************
  Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
   '**************
   ' Send Messages.
   '**************
  msg1.Label = "Test Message1"
  msg1.Body = "This is a test message with a string Body."
  msg1.Priority = 0
  
  msg2.Label = "Test Message2"
  msg2.Body = "This is a test message with a string Body."
  msg2.Priority = 7
  
  msg1.Send q
  msg2.Send q
  
  MsgBox "Both messages were sent. Check the MSMQ Explorer to see the messages in the queue."
  
 q.Close

End Sub
 

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in mqoai.h.
  Import Library: Use mqoa.lib.
  Unicode: Defined only as Unicode.

See Also

Body, Close, Create, Label, MSMQMessage, MSMQQueue, MSMQQueueInfo, Open, PathName, Send