Grouping logical messages
- You might need to process the messages in a particular order.
- You might need to process each message in a group in a related way.
In either case, retrieve the entire group with the same getting application instance.
PMO.Options = MQPMO_LOGICAL_ORDER | MQPMO_SYNCPOINT
MQPUT MD.MsgFlags = MQMF_MSG_IN_GROUP
MQPUT MD.MsgFlags = MQMF_MSG_IN_GROUP
MQPUT MD.MsgFlags = MQMF_MSG_IN_GROUP
MQPUT MD.MsgFlags = MQMF_LAST_MSG_IN_GROUP
MQCMIT
The getting application specifies the MQGMO_ALL_MSGS_AVAILABLE option for the first message in the group. This ensures that processing does not start until all the messages within the group have arrived. The MQGMO_ALL_MSGS_AVAILABLE option is ignored for subsequent messages within the group.
When the first logical message of the group is retrieved, you can use MQGMO_LOGICAL_ORDER to ensure that the remaining logical messages of the group are retrieved in order.
/* Wait for the first message in a group, or a message not in a group */
GMO.Options = MQGMO_SYNCPOINT | MQGMO_WAIT
| MQGMO_ALL_MSGS_AVAILABLE | MQGMO_LOGICAL_ORDER
do while ( GroupStatus == MQGS_MSG_IN_GROUP )
MQGET
/* Process each remaining message in the group */
...
MQCMIT
For further examples of grouping messages, see Application segmentation of logical messages and Putting and getting a group that spans units of work.
For information on allowing an application to request that a group of messages are all allocated to the same destination instance for cluster queues, see DefBind.