Spring JMS:如何配置为CachingConnectionFactory

时间:2018-06-14 19:03:46

标签: spring jms activemq spring-jms

我正在使用Spring FrameworkActiveMQ。要配置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方法,则可以选择

0 个答案:

没有答案