This first example shows a put message rule that insists that any message
being put to a queue using this queue manager must contain an MQe message
ID field:
- Java™ code
base
-
/* Only allow msgs containing an ID field to be placed on the Queue */
public void putMessage( String destQMgr, String destQ, MQeMsgObject msg,
MQeAttribute attribute, long confirmId ) {
if ( !(msg.Contains( MQe.Msg_MsgId )) ) {
throw new MQeException( Except_Rule, "Msg must contain an ID" );
}
}
- C code base
-
MQERETURN myRules_putMessage( MQeRulesPutMessage_in_ * pInput,
MQeRulesPutMessage_out_ * pOutput) {
// Only allow msgs containing an ID field to be placed on the Queue
MQERETURN rc = MQERETURN_OK;
MQEBOOL contains = MQE_FALSE;
MQeExceptBlock * pExceptBlock=(MQeExceptBlock*)(pOutput->pExceptBlock);
SET_EXCEPT_BLOCK_TO_DEFAULT(pExceptBlock);
rc = mqeFields_contains(pInput->hMsg,pExceptBlock,
&contains, MQE_MSG_MSGID);
if(MQERETURN_OK == rc && !contains) {
SET_EXCEPT_BLOCK( pExceptBlock,
MQERETURN_RULES_DISALLOWED_BY_RULE,
MQEREASON_NA);
}
}
Notice the manner in which the exception block instance is
retrieved from the output parameter structure and then set with the appropriate
return and reason codes. This is the way in which the rule function communicates
with the application, thus modifying application behavior.