MQ版本7.5.0.4
有没有一种方法可以在连接丢失时获得通知。我所能做的是,只有当超时时才会出现错误。(JMSWMQ1107: A problem with this connection has occurred.
)
mqcf.setConnectionNameList(host); // "host1(1414),host2(1414)";
mqcf.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT);
mqcf.setClientReconnectTimeout(100); // seconds
ExceptionListener exceptionListener = new ExceptionListener(){
@Override
public void onException(JMSException e) {
System.out.println(e.getErrorCode() + " " + e.getMessage());
}
};
// need to reconnect on exception..!
connection.setExceptionListener(exceptionListener);
对事件使用异常侦听器(甚至重新连接)超出了JMS规范的范围。严格的定义是,只有当连接断开时才应该触发,而正确的做法是重新创建连接。(请注意,包括MQ在内的各种供应商确实提供了扩展,因此提出要求总是值得的!)
在这里的JavaSE环境中,可以设置autoreconnect。在不受支持的托管环境中,因此您实际上必须侦听断开的连接,然后应用程序需要重新驱动createConnection()。然后"遍历"connectionNameList以查找正在运行的QM。
使用链接的异常获取更多详细信息。在我的测试中,我在没有重新连接选项的情况下结束了队列管理器,因此产生了MQRC 2161原因代码。
代码:
@Override
public void onException(JMSException e) {
System.out.println(e);//e.getErrorCode() + " " + e.getMessage());
if(e.getLinkedException() != null)
System.out.println(e.getLinkedException());
}
异常详细信息。
com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ1107: A problem with this connection has occurred.
An error has occurred with the WebSphere MQ JMS connection.
Use the linked exception to determine the cause of this error.
com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2161' ('MQRC_Q_MGR_QUIESCING').