Browsing messages when the message length is unknown
To browse a message when you do not know the size of the message, and you do not want to use the MsgId, CorrelId, or GroupId fields to locate the message, we can use the MQGMO_BROWSE_MSG_UNDER_CURSOR option:
- Issue an MQGET with:
- Either the MQGMO_BROWSE_FIRST or MQGMO_BROWSE_NEXT option
- The MQGMO_ACCEPT_TRUNCATED_MSG option
- Buffer length zero
If another program is likely to get the same message, consider using the MQGMO_LOCK option as well. MQRC_TRUNCATED_MSG_ACCEPTED should be returned.
- Use the returned DataLength to allocate the storage needed.
- Issue an MQGET with the MQGMO_BROWSE_MSG_UNDER_CURSOR.
The message pointed to is the last one that was retrieved; the browse cursor will not have moved. We can choose either to lock the message using the MQGMO_LOCK option, or to unlock a locked message using MQGMO_UNLOCK option.
The call fails if no MQGET with either the MQGMO_BROWSE_FIRST or MQGMO_BROWSE_NEXT options has been issued successfully since the queue was opened.
Parent topic:
Browsing messages on a queue
fg12900_