我正在使用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);
}
}
答案 0 :(得分:0)
我删除了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;
}
}