共用方式為


PROPID_M_XACTID

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

(Read-only, introduced in MSMQ 2.0.) The PROPID_M_XACTID property indicates which transaction sent the message.

Property ID

PROPID_M_XACTID

Type Indicator

VT_VECTOR | VT_UI1

MQPROPVARIANT Field

caub

Property Value

Identifier of the transaction. See Remarks for a description of a transaction identifier.

Remarks

This property is available for MSMQ 2.0 and later. It is used by receiving applications to verify that a message was sent from a specific transaction. The transaction identifier is a 20-byte identifier that includes the computer identifier of the sending machine (first 16 bytes) followed by a transaction sequence number (4 bytes).

Transaction identifiers are not guaranteed to be unique because the transaction sequence numbers are not persistent and they start over again at 2^20. Message Queuing guarantees only that successive transactions will have different transaction sequence numbers.

You can use PROPID_M_XACTID along with two other properties to verify transaction boundaries. These two properties are properties for identifying the first and last message sent in a transaction: PROPID_M_FIRST_IN_XACT and PROPID_M_LAST_IN_XACT.

To retrieve the transaction identifier of a message, specify PROPID_M_XACTID and a buffer consisting of 20 unsigned characters to receive its value in the MQMSGPROPS structure.

Note

The buffer must consist of exactly 20 unsigned characters. Specifying either a smaller or larger buffer will result in an error.

The size of the buffer can be specified by the constant PROPID_M_XACTID_SIZE. Then call MQReceiveMessage or MQReceiveMessageByLookupId and examine the returned identifier.

Equivalent COM Property

With COM components, the equivalent property for retrieving the transaction identifier is MSMQMessage.TransactionId.

For information on See
How transaction boundaries can be used Checking for Transaction Boundaries when Receiving Messages
Identifying the first message in the transaction PROPID_M_FIRST_IN_XACT
Identifying the last message in the transaction PROPID_M_LAST_IN_XACT

Example Code

The following code fragment shows how PROPID_M_XACTID is specified in arrays that can be used to initialize an MQMSGPROPS structure.

UCHAR rgucXactID[PROPID_M_XACTID_SIZE];  
aMsgPropId[i] = PROPID_M_XACTID;        // Property ID  
aPropVar[i].vt = VT_VECTOR | VT_UI1;    // Type indicator  
aPropVar[i].caub.pElems = rgucXactID;  
aPropVar[i].caub.cElems = PROPID_M_XACTID_SIZE;  
i++;  

The following example is included in Using Message Queuing.

For an example of See
Identifying the first and last messages in a transaction C/C++ Code Example: Checking Transaction Boundaries

See Also

Message Properties
MQMSGPROPS
PROPID_M_LAST_IN_XACT
PROPID_M_XACTID