1 回答

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
您將 IBM MQ 視為數(shù)據(jù)庫(kù),這會(huì)給您帶來(lái)各種痛苦。
這是您應(yīng)該如何檢索消息:
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());
}
}
添加回答
舉報(bào)