C example queue manager rule

The user's rules module is loaded and initialized when the queue manager is loaded into memory. This occurs as a result of calls either to mqeAdministrator_QueueManager_create() or to mqeQueueManager_new(). The setup steps are as follows:
  • The application must register a rules alias, linking the rules alias to the rules module name and entry point, by using mqeClassAlias_add(), for example:
    #define RULES_ALIAS "myAlias"
        #define MODULE_NAME "myRulesModule.dll"
        #define ENTRY_POINT "myRules_new"
        ...
     
        mqeString_newUtf8(pExceptBlock, 
                    &rulesAlias, RULES_ALIAS);
        mqeString_newUtf8(pExceptBlock, 
                    &moduleName, MODULE_NAME);
        mqeString_newUtf8(pExceptBlock, 
                    &entryPoint, ENTRY_POINT);
        mqeClassAlias_add(pExceptBlock, 
                    rulesAlias, moduleName, entryPoint);
  • The rules alias must be included in the queue manager start-up parameters passed to either mqeAdministrator_QueueManager_create() or mqeQueueManager_new(), for example.:
    MQeQueueManagerParms      qmParams;
        qmParams.hQueueStore = msgStore; /* String parameters for the*/
                              /*location of the msg store */     
        qmParams.hQueueManagerRules = rulesAlias; /* add in rules alias */
    
    
        /* Indicate what parts of the structure have been set */
        qmParams.opFlags = QMGR_Q_STORE_OP | QMGR_RULES_OP;
    
        ...
    
        rc = mqeAdministrator_QueueManager_create(hAdmin,pExceptBlock,
                                 &hQM,qmName, &qmParms, &regParms);
  • An initialization function or entry point must be supplied by the user. The following is an example of an initialization function for a rules implementation. The members of the parameter structures are documented in the MQe C Programming Reference.
    MQERETURN myRules_new( MQeRulesNew_in_ * pInput,MQeRulesNew_out_ * pOutput) {
    
        MQERETURN rc = MQERETURN_OK;
        /* declare an instance of the private data */ 
       /*structure passed around between rules invocations. */ 
       /*This holds user data which is 'global' between rules. */
        myRules * myData = NULL;
    
        /* allocate the memory for the structure */
        myData = malloc(sizeof(myRules)); 
        if(myData != NULL)    { 
       /* map user rules implementations to 
          function pointers in output parameter structure */
            pOutput->fPtrActivateQMgr   = myRules_ActivateQMgr; 
            pOutput->fPtrCloseQMgr      = myRules_CloseQMgr;              
            pOutput->fPtrDeleteMessage  = unitTestRules_DeleteMessage;
            pOutput->fPtrGetMessage     = myRules_getMessage;
            pOutput->fPtrPutMessage     = myRules_putMessage; 
            pOutput->fPtrTransmitQueue  = myRules_TransmitQueue;
            pOutput->fPtrTransmitQMgr   = myRules_TransmitQMgr;
            pOutput->fPtrActivateQueue  = myRules_activateQueue;
            pOutput->fPtrCloseQueue     = myRules_CloseQueue;
            pOutput->fPtrMessageExpired = myRules_messageExpired;
     
            /* initialize data in the private data structure */
            mydata->carryOn = MQE_TRUE;
            mydata->hAdmin = NULL;
            mydata->hThread = NULL;
            mydata->ifp = NULL;
            mydata->triggerInterval = 15000;
        
            /* now assign the private data structure to */
          /*the output parameter structure variable */
            pOutput->pPrivateData = (MQEVOID *)mydata;
        }
        else {
            /* We had a problem so clear up any strings in the structure -
                none in this case */
        }
        
        return rc;                                   
    }

The rules module is unloaded when the queue manager is freed. Note that, unlike the Java™ code base, the rules implementation is linked to the execution life cycle of a single queue manager and may not be replaced during the course of this life cycle.


Terms of use | WebSphere software

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