我使用了没有CLIENTRECONNECTTIMEOUT和CLIENTRECONNECTOPTIONS的MQQueueConnectionFactory。使用Spring JmsTemplate发送消息。
<bean id="mqCachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="mqConnectionFactory" />
<property name="sessionCacheSize" value="20" />
<property name="reconnectOnException" value="true"/>
不使用以下任何IBM MQ连接工厂设置。
firstMQConnectionFactory.setClientReconnectOptions(WMQConstancs.WMQ_CLIENT_RECONNECT;
firstMQConnectionFactory.setClientReconnectTimeout(5);
我让spring CachingConnectionFactory检测错误并尝试重新连接。
当队列管理器意外关闭时,就会出现问题。 Spring CachingConnectionFactory会检测到这一点并开始新的连接。现在,IBM MQ连接工厂尝试创建新连接。等待30分钟,然后放弃MQRC_HOST_NOT_AVAILABLE。 堆栈跟踪:
org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QMGRID' with connection mode 'Client' and host name 'QMGRHOST(port)'.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QMGR' with connection mode 'Client' and host name 'hostname(62306)'.\nCheck the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9213: A communications error for 'TCP' occurred. [1=java.net.ConnectException[Connection timed out (Connection timed out)],3=connnectUsingLocalAddress,4=TCP,5=Socket.connect]
java.net.ConnectException: Connection timed out (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_172]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_172]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_172]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_172]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_172]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_172]
at java.net.Socket.connect(Socket.java:538) ~[?:1.8.0_172]
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection$5.run(RemoteTCPConnection.java:825) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection$5.run(RemoteTCPConnection.java:816) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_172]
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:816) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.protocolConnect(RemoteTCPConnection.java:1279) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:1003) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:409) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:305) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:155) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1716) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1280) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:377) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:562) ~[com.ibm.mq.jmqi-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.msg.client.wmq.internal.WMQConnection.< init>(WMQConnection.java:356) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8474) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7814) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:299) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6016) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:111) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at com.ibm.mq.jms.MQQueueConnectionFactory.createConnection(MQQueueConnectionFactory.java:187) ~[com.ibm.mqjms-9.0.0.3.jar:9.0.0.3 - p900-003-180226]
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:403) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:343) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:321) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:236) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 67 more\n}
我们可以设置以下设置来限制此连接超时吗?
firstMQConnectionFactory.setClientReconnectTimeout(5);
当未设置CLIENTRECONNECTOPTIONS且默认情况下处于禁用状态时,此选项将生效吗?
答案 0 :(得分:0)
根据问题的描述,似乎Java在初始连接上花费了30分钟的超时时间。
MQ具有一个参数,可让您调整TCP连接超时。
根据我的判断,是否设置参数取决于Java实现和基础OS设置,超时需要花费多长时间,在您的情况下,该时间必须为30分钟,但这看起来确实很高,例如在Linux上,我相信默认值为93秒。
有两种方法可以做到这一点:
com.ibm.mq.cfg.TCP.Connect_Timeout
设置为连接超时所需的秒数。这可以通过两种方式完成:
System.setProperty('com.ibm.mq.cfg.TCP.Connect_Timeout', '5')
-Dcom.ibm.mq.cfg.TCP.Connect_Timeout=5
您还可以将Connect_Timeout=5
放在TCP:
文件的mqclient.ini
节中,并且用于JMS的IBM MQ类将从各种缺省位置进行选择。查看我对“ Where should MQClient.ini reside for an IIS Application?”的回答,以获取有关MQ将在何处查找该文件的信息。请注意,答案是考虑到Windows OS编写的,但是指向IBM Knowledge Center文档的链接也会向您显示Unix / Linux路径。
TCP:
Connect_Timeout=5