Spring AMQP和CompositeConnectionListener

时间:2016-06-06 08:41:58

标签: spring-amqp

我有一个从CompositeConnectionListener扩展的类,我有一个像这样定义的bean:

@Bean 
public CompositeConnectionListener connectionListener(){
    return new MyCompositeConnectionListener();
}

public class MyCompositeConnectionListener extends CompositeConnectionListener
{

        @Override
        public void onClose(Connection conn) 
        {
          .....

        @Override
        public void onCreate(Connection arg0) 
        {   
          .....
}

如果我关闭连接(例如从rabbitmq管理),bean正常工作(我可以检测onClose和onCreate方法)。但是,如果我再次这样做(我再次关闭连接),onclose方法不起作用,只有onCreate方法。我试图弄清楚会发生什么,但现在却不知道为什么。

由于

我使用此类只是为了在连接断开时看到错误消息。在onClose和onCreage方法中,我没什么特别有意思的:

@Override
    public void onClose(Connection conn) 
    {
        System.err.println("-------------- onClose(Connection conn) --------------");
        super.onClose(conn);
    }

    @Override
    public void onCreate(Connection arg0) 
    {       
        try {
            System.err.println("-------------- onCreate(Connection arg0)  --------------");
            super.onCreate(arg0);
        }
        catch(Exception ex)
        {
            log.error("Error.", ex);
        }
    }

这是我的日志:

Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.144] ERROR - DSISOFT3 - Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.144] ERROR - DSISOFT3 - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.145] ERROR - DSISOFT3 - Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.145] ERROR - DSISOFT3 - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.145] ERROR - DSISOFT3 - Error connecting to the server: Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.145] ERROR - DSISOFT3 - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
[06/06/2016 17:47:11.892] ERROR - DSISOFT3 - Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
[06/06/2016 17:47:11.891] WARN  - DSISOFT3 - Consumer raised exception, processing can restart if the connection factory supports it
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
[06/06/2016 17:47:11.893] ERROR - DSISOFT3 - Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
 Error (ListenerContainerConsumerFailedEvent): Consumer raised exception, attempting restart
[06/06/2016 17:47:11.893] WARN  - DSISOFT3 - Consumer raised exception, processing can restart if the connection factory supports it
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
 Error (ListenerContainerConsumerFailedEvent): Consumer raised exception, attempting restart
[06/06/2016 17:47:11.893] ERROR - DSISOFT3 - Error conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.894] ERROR - DSISOFT3 - Excepcion capturada conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.894] ERROR - DSISOFT3 - Excepcion capturada Con excepcion : com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
[06/06/2016 17:47:11.894] ERROR - DSISOFT3 - Error conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.894] ERROR - DSISOFT3 - Excepcion capturada conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.895] ERROR - DSISOFT3 - Excepcion capturada Con excepcion : com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
[06/06/2016 17:47:11.900] ERROR - DSISOFT3 - Error connecting to the server: Consumer raised exception, processing can restart if the connection factory supports it
[06/06/2016 17:47:11.900] WARN  - DSISOFT3 - Consumer raised exception, processing can restart if the connection factory supports it
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
 Error (ListenerContainerConsumerFailedEvent): Consumer raised exception, attempting restart
[06/06/2016 17:47:11.900] ERROR - DSISOFT3 - Error conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.901] ERROR - DSISOFT3 - Excepcion capturada conectando AMQP : connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:723)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:713)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:666)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:620)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:105)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:544)
    at java.lang.Thread.run(Unknown Source)
[06/06/2016 17:47:11.901] ERROR - DSISOFT3 - Excepcion capturada Con excepcion : com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - Closed via management plugin, class-id=0, method-id=0)
-------------- onClose(Connection conn) --------------
-------------- onCreate(Connection arg0)  --------------

第二次没有调用onClose方法。

0 个答案:

没有答案