Logical and physical ordering

 

Messages on queues can occur (within each priority level) in physical or logical order. Physical order is the order in which messages arrive on a queue. Logical order is when all of the messages and segments within a group are in their logical sequence, adjacent to each other, in the position determined by the physical position of the first item belonging to the group.

For a description of groups, messages, and segments, see Message groups. These physical and logical orders can differ because:

For example, the logical order might look like Figure Figure 1:

Figure 1. Logical order on a queue

These messages would appear in the following logical order on a queue:

  1. Message A (not in a group)

  2. Logical message 1 of group Y

  3. Logical message 2 of group Y

  4. Segment 1 of (last) logical message 3 of group Y

  5. (Last) segment 2 of (last) logical message 3 of group Y

  6. Logical message 1 of group Z

  7. (Last) logical message 2 of group Z

  8. Message B (not in a group)

The physical order, however, might be entirely different. As stated in topic Logical and physical ordering, the physical position of the first item within each group determines the logical position of the whole group. For example, if groups Y and Z arrived at similar times, and message 2 of group Z overtook message 1 of the same group, the physical order would look like Figure Figure 2:

Figure 2. Physical order on a queue

These messages appear in the following physical order on the queue:

  1. Message A (not in a group)

  2. Logical message 1 of group Y

  3. Logical message 2 of group Z

  4. Logical message 2 of group Y

  5. Segment 1 of (last) logical message 3 of group Y

  6. (Last) segment 2 of (last) logical message 3 of group Y

  7. Logical message 1 of group Z

  8. Message B (not in a group)

On WebSphere MQ for z/OS, the physical order of messages on the queue is not guaranteed if the queue is indexed by GROUPID.

When getting messages, we can specify MQGMO_LOGICAL_ORDER to retrieve messages in logical rather than physical order.

If you issue an MQGET call with MQGMO_BROWSE_FIRST and MQGMO_LOGICAL_ORDER, subsequent MQGET calls with MQGMO_BROWSE_NEXT must also specify this option. Conversely, if the MQGET with MQGMO_BROWSE_FIRST does not specify MQGMO_LOGICAL_ORDER, neither must the following MQGETs with MQGMO_BROWSE_NEXT.

The group and segment information that the queue manager retains for MQGET calls that browse messages on the queue is separate from the group and segment information that the queue manager retains for MQGET calls that remove messages from the queue. When you specify MQGMO_BROWSE_FIRST, the queue manager ignores the group and segment information for browsing, and scans the queue as though there were no current group and no current logical message.

Take special care if you use an MQGET call to browse beyond the end of a message group (or logical message not in a group) without specifying MQGMO_LOGICAL_ORDER. For example, if the last message in the group precedes the first message in the group on the queue, using MQGMO_BROWSE_NEXT to browse beyond the end of the group, specifying MQMO_MATCH_MSG_SEQ_NUMBER with MsgSeqNumber set to 1 (to find the first message of the next group) returns again the first message in the group already browsed. This could happen immediately, or a number of MQGET calls later (if there are intervening groups).

Avoid the possibility of an infinite loop by opening the queue twice for browse:

For further information about this, see the Application Programming Reference.

For most applications you will probably choose either logical or physical ordering when browsing. However, if you want to switch between these modes, remember that when you first issue a browse with MQGMO_LOGICAL_ORDER, your position within the logical sequence is established.

If the first item within the group is not present at this time, the group that you are in is not considered to be part of the logical sequence.

Once the browse cursor is within a group, it can continue within the same group, even if the first message is removed. Initially though, we can never move into a group using MQGMO_LOGICAL_ORDER where the first item is not present.

 

Parent topic:

The order in which messages are retrieved from a queue


fg12620_