This example shows a possible use of the message expired rule, and a copy of the message is put onto a Dead Letter Queue. Both queues and messages can have an expiry interval set. If this interval is exceeded, the message is flagged as being expired. At this point the messageExpired() rule is called. On return from this rule, the expired message is deleted.
MQEVOID myRules_messageExpired( MQeRulesMessageExpired_in_ * pInput, MQeRulesMessageExpired_out_ * pOutput) { MQERETURN rc = MQERETURN_OK; MQeExceptBlock * pExceptBlock = (MQeExceptBlock *)(pOutput->pExceptBlock); MQEBOOL contains = MQE_FALSE; MQeFieldsHndl hMsg; MQeQueueManagerHndl hQueueManager; SET_EXCEPT_BLOCK_TO_DEFAULT(pExceptBlock); /* Set re-send flag so that attempt to put message to new queue isn't rejected */ // First, clone the message as the //input parameter is read-only rc = mqeFields_clone(pInput->hMsg, pExceptBlock, &hMsg); if(MQERETURN_OK == rc) { rc = mqeFields_putBoolean(hMsg, pExceptBlock, MQE_MSG_RESEND, MQE_TRUE); if(MQERETURN_OK == rc) { // if the message contains an expiry interval field - remove it rc = mqeFields_contains(hMsg, pExceptBlock, &contains, MQE_MSG_EXPIRETIME); if(MQERETURN_OK == rc && contains) { rc = mqeFields_delete(hMsg, pExceptBlock, MQE_MSG_EXPIRETIME); } if(MQERETURN_OK == rc) { // put message onto dead letter queue MQeStringHndl hQueueManagerName; rc = mqeQueueManager_getCurrentQueueManager(pExceptBlock, &hQueueManager); if(MQERETURN_OK == rc) { rc = mqeQueueManager_getName(hQueueManager, pExceptBlock, &hQueueManagerName); if(MQERETURN_OK == rc) { // use a temporary exception block as don't care // if dead letter queue does not exist MQeExceptBlock tempExceptBlock; SET_EXCEPT_BLOCK_TO_DEFAULT(&tempExceptBlock); rc = mqeQueueManager_putMessage( hQueueManager, &tempExceptBlock, hQueueManagerName, MQE_DEADLETTER_QUEUE_NAME, hMsg, NULL, 0 ); (MQEVOID)mqeString_free(hQueueManagerName, &tempExceptBlock); } } } } } }