【问题标题】:IBM Websphere MQ - MQGET does not remove the message from the queueIBM Websphere MQ - MQGET 不会从队列中移除消息
【发布时间】:2017-03-02 09:08:54
【问题描述】:

我正在使用 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);
       }
     }

【问题讨论】:

  • 你怎么知道MQCMIT()被调用了? callback() 返回的是什么? MQCMIT() 失败了,所以事务被回滚了吗?一些printf() 语句打印出client_commit_status 的值并显示MQBACK() 是否被调用可能会清除它。
  • 我添加了 printf() 并确认正在调用 MQCMIT。我已将它们从发布的代码中删除以减少行数。
  • 好的,您是否也验证了MQBACK()没有被调用?
  • 是的。 MQBACK() 未被调用。
  • 也许我应该订阅托管队列而不是主题?

标签: c ibm-mq


【解决方案1】:

我删除了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;
                   }
        }

【讨论】:

    猜你喜欢
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多