Overview of the expiry of messages in queues
Queues can be defined with an expiry interval. If a message has remained on a queue for a period of time longer than this interval then the message is automatically deleted. When a message is deleted, a queue rule is called. Refer to the Rules topic for information on queue rules. This rule cannot affect the deletion of the message, but it does provide an opportunity to create a copy of the message.
Messages can also have an expiry interval that overrides the queue expiry interval. You can define this by adding a C MQE_MSG_EXPIRETIME or Java MQe.Msg_ExpireTime field to the message. The expiry time is either relative (expire 2 days after the message was created), or absolute (expire on November 25th 2000, at 08:00 hours). Relative expiry times are fields of type Int or MQEINT32, and absolute expiry times are fields of type Long or MQEINT64.
/* create a new message */ MQeMsgObject msgObj = new MQeMsgObject(); msgObj.putAscii( "MsgData", getMsgData() ); /* expiry time of sixty seconds after message was created */ msgObj.putInt( MQe.Msg_ExpireTime, 60000 );
/* create a new message */ MQeMsgObject msgObj = new MQeMsgObject(); msgObj.putAscii( "MsgData", getMsgData() ); /* create a Date object for 15th May 2001, 15:25 hours */ Calendar calendar = Calendar.getInstance(); calendar.set( 2001, 04, 15, 15, 25 ); Date expiryTime = calendar.getTime(); /* add expiry time to message */ msgObj.putLong( MQe.Msg_ExpireTime, expiryTime.getTime() ); /* put message onto queue */ qmgr.putMessage( null, "MyQueue", msgObj, null, 0 );
Checking for expired messages
Explanation of when MQe checks for expired messagesAssurance of expiry
Explains how to ensure message expiry
Parent topic: What are MQe messages?