Id
MSMQMessage

Read-only. The Id property identifies the message using an MSMQ-generated message identifier.

Type: Variant (array of bytes)
Run time: read-only

Syntax

object.Id
 
Syntax Element Description
object Message (MSMQMessage) object from queue.

Return Values

20-byte message identifier (array of bytes).

Remarks

MSMQ generates a 20-byte message identifier and attaches it to the message when the message is sent. The identifier is an array of bytes that can be read by either the sending or receiving application.

MSMQ generates message identifiers for all messages, including acknowledgment messages generated by MSMQ and MSMQ Connector applications. When an acknowledgment message is created, the identifier of the original message can be found in the acknowledgment message's CorrelationId property.

Example

This example locates a destination queue (creating one if one does not exist), sends two messages to the queue, and then reads the message and displays the message identifier.

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 query As New MSMQQuery
Dim qinfos As MSMQQueueInfos
Dim qinfoDest As MSMQQueueInfo
Dim q As MSMQQueue
Dim msgSent1 As New MSMQMessage
Dim msgSent2 As New MSMQMessage
Dim msgRead As MSMQMessage
Dim strID As String             'String representation of ID.

Private Sub Form_Click()
   
   
   '**********************************
   ' Locate destination queue
   '(create one if one doesn't exist).
   '**********************************
   
   Set qinfos = query.LookupQueue(Label:="Destination Queue")
   qinfos.Reset
   Set qinfoDest = qinfos.Next
   If qinfoDest Is Nothing Then
      Set qinfoDest = New MSMQQueueInfo
      qinfoDest.PathName = ".\DestQueue"
      qinfoDest.Label = "Destination Queue"
      qinfoDest.Create
   End If
   
   '************************
   ' Open destination queue.
   '************************
   Set q = qinfoDest.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
   
   '**************
   ' Send Messages.
   '**************
   msgSent1.Label = "Test Message"
   msgSent1.Body = "This message tests the message identifier."
   msgSent1.Send q
   For counter = LBound(msgSent.Id) To UBound(msgSent.Id)
          strID = strID & Hex(msgSent.Id(Counter))
   Next counter
   MsgBox "Message (" + StrID + ") was sent to the queue."
   strID = ""
   
   msgSent2.Label = "Test Message"
   msgSent2.Body = "This message tests the message identifier."
   msgSent2.Send q
   For counter = LBound(msgSent2.Id) To UBound(msgSent2.Id)
          strID = strID & Hex(msgSent2.Id(Counter))
   Next counter

   MsgBox "Message (" + strID + ") was sent to the queue."
   strID = ""
   q.Close
  
   '************************************
   ' Read the message in the destination
   ' queue and display its identifier.
   '************************************
   
   Set q = qinfoDest.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
   Set msgRead = q.Receive (ReceiveTimeout:=0)
   
   While Not msgRead Is Nothing
      For Counter = LBound(msgRead.Id) To UBound(msgRead.Id)
          strID = strID & Hex(msgRead.Id(Counter))
      Next Counter
      MsgBox "The message " + strID + " was removed from the queue."
      strID = ""
      Set msgRead = q.Receive
  Wend
  
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, MSMQQuery, MSMQQueue, MSMQQueueInfo, MSMQQueueInfos, Next, Open, PathName, Receive, Reset, Send