I love going to customers because they use MQ in many different ways.
A customer's problem was that they send a request to a back end, but sometimes the back end does not reply fast enough. The question was, how can they use MQ to tell an application when it has not received a message within a time period.
Thanks to Gwydion Tudur for the answer below.
The plan was to put a message to a local queue with an expiry time as well as sending the message to the back end. If the backend replies in time then get the message from the local queue. If the backend does not reply then if the local message expires. The expiry report message, put to the reply to queue in the MQMD of the local message, can be used to trigger an application to respond to the end user.
Will this work ? Yes , but not perhaps as expected.
The next question was, if I specify time out of 2 seconds, will the expiry report message always be delivered after 2 seconds. The answer is possibly not.
If there is high activity on the local queue (frequent MQGETs) and the queue depth is low, then you may get your expiry event message close to your expiry time. If the activity on the queue is very low then you event report may be generated after EXPRYINT seconds.
Digging into this in more detail...
There are two ways of checking for expiry
- When an application does and MQGET on a queue, and the queue manager comes across a message where the expiry time has passed, then it will delete the message and generate the expired message report. If there are 1000 messages on the queue, and it takes 1 millisecond to process each message then it will take 1 second before the last message is processed, and so the the report message from the last message would be generated after 1 second. This relies on applications performing frequent MQGETs on the queue.
- The queue manager can be enabled to check queues for expired messages. See the queue manager attribute EXPRYINT. There is one QMGR task which checks all queues; EXPRYINT specifies (in seconds) how often this task runs to scan queues and discard expired messages. The minimum is 5 seconds. If you have many queues or queues with many messages this can be disruptive. If you have a queue with millions of messages, and these messages are on a page set, then these messages will have to be read in and checked, this may take over a second. In this case it is unlikely that your message with a 2 seconds expiry will get the report messages generated close to 2 seconds.