1 回答
TA贡献1833条经验 获得超4个赞
您将 IBM MQ 视为数据库,这会给您带来各种痛苦。
这是您应该如何检索消息:
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING;
gmo.waitInterval = 5000; // wait up to 5 seconds
MQMessage receiveMsg = null;
boolean getMore = true;
while(getMore)
{
receiveMsg = new MQMessage();
try
{
// get the message on the queue
queue.get(receiveMsg, gmo);
/*
* Now go do something with the message
*/
}
catch (MQException e)
{
if ( (e.completionCode == CMQC.MQCC_FAILED) &&
(e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) )
{
// No message - loop again
}
else
{
System.out.println("MQException: " + e.getLocalizedMessage());
System.out.println("CC=" + e.completionCode + " : RC=" + e.reasonCode);
getMore = false;
}
}
catch (IOException e)
{
System.out.println("IOException:" +e.getLocalizedMessage());
}
}
添加回答
举报