[英]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. 我正在使用Websphere版本9,并使用示例程序进行订阅以订阅主题。 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. 问题是-在每次MQGET和commit之后,不会清除队列中的消息。
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. 我删除了
MQSUB
调用,并将其替换为以下代码。 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. 现在,
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.