【发布时间】:2013-10-10 21:37:30
【问题描述】:
我继承了下面这段可爱的代码。
按照我的阅读方式,开发者做了三个假设:
- MQQueueManager 实例不一定在 isConnected() 返回 true 的状态下创建
- 如果它是在 isConnected() == false 状态下创建的,则状态可能会“稍后”更改,因此会出现超时代码
- 如果您尝试从断开连接的 MQQueueManager 创建访问队列,它不会抛出异常。
我希望 MQQueueManager 实例在 isConnected() == true 状态下创建,此状态可能会在稍后更改(网络故障等),并且此状态更改(isConnected() == false)会导致队列上的操作失败并出现 MQException。
文档对这些点保持沉默,但要注意在手动断开 MQQueueManager 后重新连接到队列的唯一方法是创建一个新的 MQQueueManager 实例。
谁能帮我直截了当?
qMgr = new MQQueueManager( qManager );
// Set up the options on the queue we wish to open...
// Note. All WebSphere MQ Options are prefixed with MQC in Java.
final int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open,
// and the open options...
queue = qMgr.accessQueue( queueName, openOptions );
// Set the get message options...
final MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the
// defaults
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = 1000;
connectionStatus = CONNECTING;
int timeOutCounter = 0;
while(!qMgr.isConnected()) {
InboundMsgTask.sleep(1000);
timeOutCounter++;
if(timeOutCounter > 4) {
connectionStatus = TIME_OUT;
return;
}
}
connectionStatus = CONNECTED;
【问题讨论】:
标签: ibm-mq