首先看下警告日志
在生产服务器上,如果长期没有使用到队列,MQ Produce和consumer端同时报如下错误,导致不能正常工作。
01-30 20:06:59.479 WARN [ActiveMQ InactivityMonitor Worker] (FailoverTransport.java:278) -Transport (tcp://10.27.155.123:61616?wireFormat.maxInactivityDuration=100) failed , attempting to automatically reconnect: org.apache.activemq.transport.InactivityIOException: Channel was inactive for too (>100) long: tcp://10.27.155.123:61616
01-30 21:37:08.817 WARN [ActiveMQ InactivityMonitor Worker] (FailoverTransport.java:278) -Transport (tcp://10.27.155.123:61616?wireFormat.maxInactivityDuration=100) failed , attempting to automatically reconnect: org.apache.activemq.transport.InactivityIOException: Channel was inactive for too (>100) long: tcp://10.27.155.123:61616
官网给出的解释如下:
2012-06-26 17:13:55,712 | DEBUG | 30000 ms elapsed since last read check. | org.apache.activemq.transport.AbstractInactivityMonitor | InactivityMonitor ReadCheck
2012-06-26 17:13:55,712 | DEBUG | No message received since last read check for tcp:///127.0.0.1:52659! Throwing InactivityIOException. | org.apache.activemq.transport.AbstractInactivityMonitor | InactivityMonitor ReadCheck
2012-06-26 17:13:55,714 | DEBUG | Transport Connection to: tcp://127.0.0.1:52659 failed:
org.apache.activemq.transport.InactivityIOException: Channel was inactive for too (>30000) long: tcp://127.0.0.1:52659 |
org.apache.activemq.broker.TransportConnection.Transport | InactivityMonitor Async Task:
java.util.concurrent.ThreadPoolExecutor$Worker@6a346239
org.apache.activemq.transport.InactivityIOException: Channel was inactive for too (>30000) long: tcp://127.0.0.1:52659
at org.apache.activemq.transport.AbstractInactivityMonitor$4.run(AbstractInactivityMonitor.java:187)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Setting transport.useInactivityMonitor=false will disable the InactivityMonitor. Configuring wireFormat.maxInactivityDuration=0 will achieve the same result.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http:///config/1.0">
<broker brokerName="receiver">
<transportConnectors>
<transportConnector uri="tcp://localhost:62002"/>
</transportConnectors>
<networkConnectors>
<networkConnector uri="static:(tcp://somehost:62001?wireFormat.maxInactivityDuration=0)"/>
</networkConnectors>
<persistenceAdapter>
<memoryPersistenceAdapter/>
</persistenceAdapter>
</broker>
</beans>
解决方案如下:
查看配置,在activemq的 conf/activemq.xml 里设置了InactivityMonitor的连接超时时间导致,如:
通过设置连接URL的属性: tcp:/ / 0.0.0.0:61616 ? wireFormat.maxInactivityDuration = 30000,表示如果30秒没有数据被读取,接InactivityMonitor假定有一个连接的问题。 InactivityMonitor抛出一个InactivityIOException和关闭相关的转换连接.
解决方案:wireFormat.maxInactivityDuration=0,禁用InactivityMonitor
uri="tcp://0.0.0.0:61616?wireFormat.maxInactivityDuration=30000"
修改为
uri="tcp://0.0.0.0:61616?wireFormat.maxInactivityDuration=0"