Search code examples
message-queueibm-mqcorrelated

Will a correlated MQGET clear out other expired messages on a queue?


When you do a "normal" MQGET on an MQ queue, my understanding is that expired messages (those whose expiry time have passed) will not be retrieved. Instead, they will be thrown away and the next message in the queue attempted.

My question has to do with correlated MQGET operations. Since they are specifically looking for a message with a given correlation ID, do they bypass the normal mechanism which would result in expired messages being discarded?

In other words, since they're looking for a specific message, do they just go straight for that message?

Obviously, if that message has expired, it will be discarded, my question has to do with the messages in the queue before that point.


Solution

  • An expired message will never be returned to your application whether you get it directly by MsgId or CorrelId, or whether you get-next to it.

    Expired messages are cleared off the queue by an internal task as well as by passing MQGETs noticing them.

    This is detailed here on developerWorks, where it states:

    To remedy this situation [expired messages being left on queues because no MQGETs are trying to read them] on the z/OS platform, you can specify a time period for messages to be removed with the EXPRYINT (expiry interval) queue manager attribute. Each time the expiry interval is reached, the queue manager scans queues to discard expired messages.

    If your queue manager is located on a UNIX distributed platform, MQ V6 has incorporated an expirer task that works in a similar fashion for distributed platforms.

    IBM also has a more official technote detailing the behaviour, located here, and stating:

    Beginning in WMQ V6.0, functionality has been added to internally discard expired messages silently.

    When a message expires, it will be discarded when: an MQGET which matches the message is issued, or It is internally removed by the queue manager's expirer task.

    The internal expirer task runs every 300 seconds (5 minutes), by default. If you wish to alter the frequency of this task, you may use the 'ExpiryInterval' setting. This value is configured in seconds, with a range from 1 to 1,000,000 seconds. If you set the value to '0', you will disable the task.

    On z/OS, 'ExpiryInterval' is a queue manager attribute. On distributed platforms, 'ExpiryInterval' can be added to the 'TuningParameters' stanza in the queue manager's qm.ini file.