This is a period of time expressed in tenths of a second, set by the application that puts the message. The message becomes eligible to be discarded if it has not been removed from the destination queue before this period of time elapses.
For example, to set one minute for the expiry time, you need to set MQMD.Expiry to 600.
The value is decremented to reflect the time that the message spends on the destination queue, and also on any intermediate transmission queues if the put is to a remote queue. It can also be decremented by message channel agents to reflect transmission times, if these are significant. Likewise, an application forwarding this message to another queue might decrement the value if necessary, if it has retained the message for a significant time. However, the expiration time is treated as approximate, and the value need not be decremented to reflect small time intervals.
When the message is retrieved by an application using the MQGET call, the
field represents the expiry time that still remains.
After a message's expiry time has elapsed, it becomes eligible to be discarded by the queue manager. The message is discarded when a browse or nonbrowse MQGET call occurs that would have returned the message had it not already expired. For example, a nonbrowse MQGET call with the
MatchOptions field in MQGMO set to MQMO_NONE reading from a FIFO ordered queue discards all the expired messages up to the first unexpired message. With a priority ordered queue, the same call will discard expired messages of higher priority and messages of an equal priority that arrived on the queue before the first unexpired message.
A message that has expired is never returned to an application (either by a browse or a non-browse MQGET call), so the value in the
Expiry field of the message descriptor after a successful MQGET call is either greater than zero, or the special value MQEI_UNLIMITED.
If a message is put on a remote queue, the message might expire (and be discarded) while it is on an intermediate transmission queue, before the message reaches the destination queue.
A report is generated when an expired message is discarded, if the message specified one of the MQRO_EXPIRATION_* report options. If none of these options is specified, no such report is generated; the message is assumed to be no longer relevant after this time period (perhaps because a later message has superseded it).
- If a message is put with an
Expirytime of zero or a number greater than 999 999 999, the MQPUT or MQPUT1 call fails with reason code MQRC_EXPIRY_ERROR; no report message is generated in this case.
To enable reason code 2013, MQRC_EXPIRY_ERROR, you must enable the environment variable AMQ_ENFORCE_MAX_EXPIRY_ERROR.The following uses an example for Linux®:
Note that the:
$ export AMQ_ENFORCE_MAX_EXPIRY_ERROR=True
- Important thing is to export the variable
- Actual value is ignored, however, using
Truemight be helpful when reviewing the setup.
- Because a message with an expiry time that has elapsed might not be discarded until later, there might be messages on a queue that have passed their expiry time, and that are not therefore eligible for retrieval. These messages nevertheless count toward the number of messages on the queue for all purposes, including depth triggering.
- An expiration report is generated, if requested, when the message is discarded, not when it becomes eligible for discarding.
- Discarding an expired message, and generating an expiration report if requested, are never part of the application's unit of work, even if the message was scheduled for discarding as a result of an MQGET call operating within a unit of work.
- If a nearly-expired message is retrieved by an MQGET call within a unit of work, and the unit of work is subsequently backed out, the message might become eligible to be discarded before it can be retrieved again.
- If a nearly-expired message is locked by an MQGET call with MQGMO_LOCK, the message might become eligible to be discarded before it can be retrieved by an MQGET call with MQGMO_MSG_UNDER_CURSOR; reason code MQRC_NO_MSG_UNDER_CURSOR is returned on this subsequent MQGET call if that happens.
- When a request message with an expiry time greater than zero is retrieved, the application can
take one of the following actions when it sends the reply message:
- Copy the remaining expiry time from the request message to the reply message.
- Set the expiry time in the reply message to an explicit value greater than zero.
- Set the expiry time in the reply message to MQEI_UNLIMITED.
- Trigger messages are always generated with MQEI_UNLIMITED.
- A message (normally on a transmission queue) that has a
Formatname of MQFMT_XMIT_Q_HEADER has a second message descriptor within the MQXQH. It therefore has two
Expiryfields associated with it. The following additional points should be noted in this case:
- When an application puts a message on a remote queue, the queue manager places the message
initially on a local transmission queue, and prefixes the application message data with an MQXQH
structure. The queue manager sets the values of the two
Expiryfields to be the same as that specified by the application.
If an application puts a message directly on a local transmission queue, the message data must already begin with an MQXQH structure, and the format name must be MQFMT_XMIT_Q_HEADER. In this case, the application need not set the values of these two
Expiryfields to be the same. (The queue manager checks that the
Expiryfield within the MQXQH contains a valid value, and that the message data is long enough to include it). For an application that can write directly to the transmission queue, the application has to create a transmission queue header with the embedded message descriptor. However, if the expiry value in the message descriptor written to the transmission queue is inconsistent with the value in the embedded message descriptor, an expiry error rejection occurs.
- When a message with a
Formatname of MQFMT_XMIT_Q_HEADER is retrieved from a queue (whether this is a normal or a transmission queue), the queue manager decrements both these
Expiryfields with the time spent waiting on the queue. No error is raised if the message data is not long enough to include the
Expiryfield in the MQXQH.
- The queue manager uses the
Expiryfield in the separate message descriptor (that is, not the one in the message descriptor embedded within the MQXQH structure) to test whether the message is eligible for discarding.
- If the initial values of the two
Expiryfields are different, the
Expirytime in the separate message descriptor when the message is retrieved might be greater than zero (so the message is not eligible for discarding), while the time according to the
Expiryfield in the MQXQH has elapsed. In this case the
Expiryfield in the MQXQH is set to zero.
- When an application puts a message on a remote queue, the queue manager places the message initially on a local transmission queue, and prefixes the application message data with an MQXQH structure. The queue manager sets the values of the two
- The expiry time on a reply message returned from the IMS bridge is unlimited unless MQIIH_PASS_EXPIRATION is set in the Flags field of the MQIIH. See Flags for more information.
- The message has an unlimited expiration time.
This is an output field for the MQGET call, and an input field for the MQPUT and MQPUT1 calls. The initial value of this field is MQEI_UNLIMITED.