简体   繁体   中英

IBM Websphere MQ - MQGET does not remove the message from the queue

I am using websphere version 9 and using the sample program for subscription to subscribe to a topic. Following is my code. I have introduced unit of work into the sample.

The problem is - After each MQGET and commit the message in the queue does not get cleared.

Any thoughts ? Is it something to do with the way the queues were created.? persistent, durable etc.. ?

 MQSUB(Hcon,                       /* connection handle            */
         &sd,                        /* object descriptor for queue  */
         &Hobj,                      /* object handle (output)       */
         &Hsub,                      /* object handle (output)       */
         &S_CompCode,                /* completion code              */
         &Reason);                   /* reason code                  */
   CompCode = S_CompCode;           /* use MQOPEN result for initial test  */

   gmo.Options =   MQGMO_WAIT         /* wait for new messages       */
                 | MQGMO_SYNCPOINT    /* transaction              */
                 | MQGMO_CONVERT;     /* convert if necessary        */

   gmo.WaitInterval = MQWI_UNLIMITED;
    while (CompCode != MQCC_FAILED)
   {
     buflen = sizeof(buffer) - 1; /* buffer size available for GET   */
     memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));
     memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));
     md.Encoding       = MQENC_NATIVE;
     md.CodedCharSetId = MQCCSI_Q_MGR;

     /************************************************************************/
           /* Start a unit of work                                                 */
     /************************************************************************/
     MQBEGIN (Hcon, &bo, &CompCode, &Reason);

     MQGET(Hcon,                /* connection handle                 */
           Hobj,                /* object handle                     */
           &md,                 /* message descriptor                */
           &gmo,                /* get message options               */
           buflen,              /* buffer length                     */
           buffer,              /* message buffer                    */
           &messlen,            /* message length                    */
           &CompCode,           /* completion code                   */
           &Reason);            /* reason code                       */

     /****************************************************************/
     /*   Display each message received                              */
     /****************************************************************/
     if (CompCode != MQCC_FAILED)
     {
       buffer[messlen] = '\0';            /* add terminator          */
       char* strings[] = {buffer};
       bool client_commit_status = callback(strings);
       if(client_commit_status){
            MQCMIT(Hcon, &CompCode, &Reason);
            if (MQCC_OK != CompCode){
                MQBACK(Hcon, &CompCode, &Reason);
            }
       }else{
            MQBACK(Hcon, &CompCode, &Reason);
       }
     }

I removed the MQSUB call and replaced it with the following code. Since all my subscriptions are directed to a destination queue by configuration, I stared listening to the queue directly. Now the MQGET clears the queue.

if (strlen(target_queue_name)) {
                   strncpy(od.ObjectName, target_queue_name, MQ_Q_NAME_LENGTH);
                   MQOPEN(Hcon, &od, MQOO_INPUT_AS_Q_DEF | MQOO_FAIL_IF_QUIESCING | MQOO_INQUIRE,
                         &Hobj, &CompCode, &Reason);
                   if (CompCode != MQCC_OK) {
                            printf("MQOPEN ended with reason code %d\n", Reason);
                            return (int)Reason;
                   }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM