我正在使用Spring Framework
和ActiveMQ
。要配置CachingConnectionFactory
,请使用以下内容:
@Bean
CachingConnectionFactory selectedCachingConnectionFactoryInstanceB(
ActiveMQConnectionFactory selectedConnectionFactoryInstanceB)
throws JMSException {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
....
cachingConnectionFactory.createConnection().start();
cachingConnectionFactory.setExceptionListener(new ConnectionFactoryExceptionListenerAbc());
return cachingConnectionFactory;
}
ConnectionFactoryExceptionListenerAbc
类是:
public class ConnectionFactoryExceptionListenerAbc implements ExceptionListener {
private static final Logger logger = LoggerFactory.getLogger(ConnectionFactoryExceptionListenerAbc.class);
@Override
public void onException(JMSException exception) {
logger.error("ABC ABC JMSException: {}", exception.toString());
}
}
当ActiveMQ
服务器关闭时ConnectionFactoryExceptionListenerAbc
' onException
方法永远不会执行。并出现以下错误堆栈跟踪:
o.s.j.c.CachingConnectionFactory - Encountered a JMSException - resetting the underlying JMS Connection
javax.jms.JMSException: java.io.EOFException
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:54)
at org.apache.activemq.ActiveMQConnection.onAsyncException(ActiveMQConnection.java:1952)
at org.apache.activemq.ActiveMQConnection.onException(ActiveMQConnection.java:1971)
at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:114)
at org.apache.activemq.transport.ResponseCorrelator.onException(ResponseCorrelator.java:126)
at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:114)
at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:114)
at org.apache.activemq.transport.WireFormatNegotiator.onException(WireFormatNegotiator.java:173)
at org.apache.activemq.transport.AbstractInactivityMonitor.onException(AbstractInactivityMonitor.java:345)
at org.apache.activemq.transport.TransportSupport.onException(TransportSupport.java:96)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:219)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException: null
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:268)
at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:240)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:232)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:215)
... 1 common frames omitted
此行为仅发生在CachingConnectionFactory
,配置@Bean
的其他ActiveMQConnectionFactory
以及其中每个与其他实现ExceptionListener
的类一起使用并再次使用{ {1}}如何预期
之后通过其他帖子进行研究:
setExceptionListener
扩展CachingConnectionFactory
,后者已实现SingleConnectionFactory
。
那么如何才能使用自定义ExceptionListener
并且如果需要重用ExceptionListener
onException
方法,则可以选择