gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:49:32 24 4
gpt4 key购买 nike

我使用的是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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com