c - IBM Websphere MQ - MQGET 不会从队列中删除消息

标签 c ibm-mq

我使用的是websphere版本9,并使用订阅示例程序来订阅主题。以下是我的代码。我已将工作单元引入到示例中。

问题是 - 每次 MQGET 和提交后,队列中的消息不会被清除。

有什么想法吗?这与队列的创建方式有关吗?持久、耐用等..?

 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);
       }
     }

最佳答案

我删除了 MQSUB 调用,并将其替换为以下代码。由于我的所有订阅都通过配置定向到目标队列,因此我开始直接监听队列。现在 MQGET 清除队列。

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;
                   }
        }

关于c - IBM Websphere MQ - MQGET 不会从队列中删除消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42551043/

相关文章:

c# - 在 .NET 应用程序中将 Websphere MQ 与 JMS 结合使用

c - 从文件读取时如何跳过字符串中的空格

python - 在Python中设计类似C的结构的最佳方法

java - Websphere MQ - Java 应用程序 - 启用日志记录

java - 消息重新传递 ibm mq

ibm-mq - 将消息从一个本地队列推送到同一队列管理器中的另一个远程队列

c - 识别gtk中滚动条的向上/向下移动

c - 编译为 GUI 的 Win32 GUI 应用程序需要使用 C 语言的控制台

c - 舍入错误 : The Sum

ibm-mq - WebSphere MQ 中的 MQRC 资源问题