Browsing messages in groups
In this example, the application browses through each message on the queue, in logical order.
Messages on the queue might be grouped. For grouped messages, the application does not want to start processing any group until all the messages within it have arrived. MQGMO_ALL_MSGS_AVAILABLE is therefore specified for the first message in the group; for subsequent messages in the group, this option is unnecessary.
MQGMO_WAIT is used in this example. However, although the wait can be satisfied if a new group arrives, for the reasons in Browsing messages in logical order, it is not satisfied if the browse cursor has already passed the first logical message in a group, and the remaining messages now arrive. Nevertheless, waiting for a suitable interval ensures that the application does not constantly loop while waiting for new messages or segments.
MQGMO_LOGICAL_ORDER is used throughout, to ensure that the scan is in logical order. This contrasts with the destructive MQGET example, where because each group is being removed, MQGMO_LOGICAL_ORDER is not used when looking for the first (or only) message in a group.
It is assumed that the application's buffer is always large enough to hold the entire message, whether or not the message has been segmented. MQGMO_COMPLETE_MSG is therefore specified on each MQGET.
The following gives an example of browsing logical messages in a group:/* Browse the first message in a group, or a message not in a group */ GMO.Options = MQGMO_BROWSE_NEXT | MQGMO_COMPLETE_MSG | MQGMO_LOGICAL_ORDER | MQGMO_ALL_MSGS_AVAILABLE | MQGMO_WAIT MQGET GMO.MatchOptions = MQMO_MATCH_MSG_SEQ_NUMBER, MD.MsgSeqNumber = 1 /* Examine first or only message */ ... GMO.Options = MQGMO_BROWSE_NEXT | MQGMO_COMPLETE_MSG | MQGMO_LOGICAL_ORDER do while ( GroupStatus == MQGS_MSG_IN_GROUP ) MQGET /* Examine each remaining message in the group */ ...
The group is repeated until MQRC_NO_MSG_AVAILABLE is returned.
Parent topic: Browsing messages in logical order