To get a particular message from a queue, use the MsgId
and CorrelId fields of the MQMD structure. Note,
however, that applications can explicitly set these fields, so the values you
specify may not identify a unique message. Table 5 shows which message is retrieved for the possible settings
of these fields. These fields are ignored on input if you specify
MQGMO_MSG_UNDER_CURSOR in the GetMsgOpts
parameter of the MQGET call.
Table 5. Using message and correlation identifiers
To retrieve ... | MsgId | CorrelId |
---|---|---|
First message in the queue | MQMI_NONE | MQCI_NONE |
First message that matches MsgId | Nonzero | MQCI_NONE |
First message that matches CorrelId | MQMI_NONE | Nonzero |
First message that matches both MsgId and CorrelId | Nonzero | Nonzero |
In each case, first means the first message that satisfies the selection criteria (unless MQGMO_BROWSE_NEXT is specified, when it means the next message in the sequence satisfying the selection criteria).
On return, the MQGET call sets the MsgId and CorrelId fields to the message and correlation identifiers (respectively) of the message returned (if any).
If you set the Version field of the MQMD structure to 2
or 3, you can use the GroupId,
MsgSeqNumber, and Offset
fields. Table 6 shows which message is retrieved for the possible
settings of these fields.
Table 6. Using the group identifier
To retrieve ... | Match options |
---|---|
First message in the queue | MQMO_NONE |
First message that matches MsgId | MQMO_MATCH_MSG_ID |
First message that matches CorrelId | MQMO_MATCH_CORREL_ID |
First message that matches GroupId | MQMO_MATCH_GROUP_ID |
First message that matches MsgSeqNumber | MQMO_MATCH_MSG_SEQ_NUMBER |
First message that matches MsgToken | MQMO_MATCH_MSG_TOKEN |
First message that matches Offset | MQMO_MATCH_OFFSET |
|
Notes:
On WebSphere MQ for z/OS, the queue attribute, IndexType, can be used to increase the speed of MQGET operations on the queue. For more information, see Type of index.