2017-07-18 378 views
1

我的应用程序后会失去连接到RabbitMQ的服务器,我在日志中看到RabbitMQ:重新连接后为什么不重新打开频道?

ERROR ... o.s.a.r.c.CachingConnectionFactory : Channel shutdown: connection error 

然后当我的应用程序重新连接到RabbitMQ的服务器,我在日志中看到

INFO ... Created new connection: [email protected] [delegate=amqp://******] 

但是当应用程序重新连接到RabbitMQ服务器,通道不会重新打开,在RabbitMQ管理控制台中,我可以在'Channels'选项卡中看到没有任何通道。

在重新连接后的RabbitMQ服务器日志:

=INFO REPORT==== 13-Jul-2017::10:33:39 === 
accepting AMQP connection (*.*.*.*:* -> *.*.*.*:5672) 

=INFO REPORT==== 13-Jul-2017::10:33:39 === 
Connection (*.*.*.*:* -> *.*.*.*:5672) has 
a client-provided name: rabbitConnectionFactory#1 

=INFO REPORT==== 13-Jul-2017::10:33:39 === 
connection (*.*.*.*:* -> *.*.*.*:5672 - 
rabbitConnectionFactory#1): user '***' authenticated and granted access to vhost '***' 

我使用Spring 1.5.3引导和弹簧引导起动AMQP

它看起来像Spring AMQP 1.7禁用的RabbitMQ客户端的“enableAutomaticRecovery”,并使用它自己的恢复机制

的4.0.x的客户端能够自动恢复默认;在与此功能兼容的同时,Spring AMQP具有自己的恢复机制,通常不需要客户端恢复功能。建议禁用AMQP客户端的自动恢复功能,以避免收到AutoRecoverConnectionNotCurrentlyOpenException■当经纪人是可用的,但连接尚未恢复。从版本1.7.1开始,Spring AMQP将禁用它,除非您显式创建自己的RabbitMQ连接工厂并将其提供给CachingConnectionFactory。由RabbitConnectionFactoryBean创建的RabbitMQ ConnectionFactory实例也将默认禁用该选项。

我不知道这有什么关系的问题。

需要注意的是,如果我关闭我的应用程序并重新启动它,它的行为如预期。

回答

0

春AMQP关闭automaticRecovery通过default

private static com.rabbitmq.client.ConnectionFactory newRabbitConnectionFactory() { 
    com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); 
    connectionFactory.setAutomaticRecoveryEnabled(false); 
    return connectionFactory; 
} 

您可以通过RabbitConnectionFactoryBean开启:

/** 
* Set to true to enable amqp-client automatic recovery. Note: Spring AMQP 
* implements its own connection recovery and this is generally not needed. 
* @param automaticRecoveryEnabled true to enable. 
* @since 1.7.1 
*/ 
public void setAutomaticRecoveryEnabled(boolean automaticRecoveryEnabled) { 
    this.connectionFactory.setAutomaticRecoveryEnabled(automaticRecoveryEnabled); 
} 

春季AMQP外的开箱自动恢复好听众的容器,但我想你处理RabbitTemplate。因此,可以考虑将其打开:http://docs.spring.io/spring-amqp/reference/html/_reference.html#auto-recovery

相关问题