我们在绑定到Rabbit MQ实例的Java应用程序的日志中遇到以下异常的情况。
这是必须注意的事情,它表示Spring AMQP的实现中存在问题,还是可以忽略的事情?在后一种情况下,此类错误的根本原因是什么?
com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)
at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:927)
at com.rabbitmq.client.impl.AMQConnection.close(AMQConnection.java:1042)
at com.rabbitmq.client.impl.AMQConnection.close(AMQConnection.java:971)
at com.rabbitmq.client.impl.AMQConnection.close(AMQConnection.java:955)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.close(AutorecoveringConnection.java:305)
at org.springframework.amqp.rabbit.connection.SimpleConnection.close(SimpleConnection.java:76)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory$3.handleRecovery(AbstractConnectionFactory.java:389)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory$3.handleRecoveryStarted(AbstractConnectionFactory.java:383)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.notifyRecoveryListenersStarted(AutorecoveringConnection.java:652)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.beginAutomaticRecovery(AutorecoveringConnection.java:570)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.access$000(AutorecoveringConnection.java:63)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection$3.recoveryCanBegin(AutorecoveringConnection.java:513)
at com.rabbitmq.client.impl.AMQConnection.notifyRecoveryCanBeginListeners(AMQConnection.java:754)
at com.rabbitmq.client.impl.AMQConnection.doFinalShutdown(AMQConnection.java:731)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:615)
at java.base/java.lang.Thread.run(Unknown Source)
[com.rabbitmq.client.RecoveryListener
中的org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
接口的实现似乎无条件地关闭连接,无论其“打开”状态如何。
@Override
public void handleRecoveryStarted(Recoverable recoverable) {
handleRecovery(recoverable);
}
@Override
public void handleRecovery(Recoverable recoverable) {
try {
connection.close();
}
catch (Exception e) {
AbstractConnectionFactory.this.logger.error("Failed to close auto-recover connection", e);
}
}
[spring-amqp
和spring-rabbit
版本是1.7.14
谢谢,
您不应该在Spring中使用自动恢复;它比amqp客户端早几年就拥有自己的恢复机制。