Message expiry

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 Queue rules for more information. 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.

In the example below, the message expires 60 seconds after it is created (60000 milliseconds = 60 seconds).
/* 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 );
In the example below, the message expires on 15th May 2001, at 15:25 hours.
/* 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 );
To set a relative expiry time use the following on a message handle:
mqeFields_putInt32(pErrorBlock, hMsg, relativeTime);
To set an absolute expiry time use:
mqeFields_putInt64(pErrorBlock,hMsg, absoluteTime);

All Times are in milliseconds


Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.