当RabbitMq服务器可用时向Rabbitmq Exchange发送一些消息并使用Rabbit Listener消耗基于Queuename的消息。但是当队列中没有消息总是
时我的代码如下所示
<bean id="rabbitListenerContainerFactory" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
<property name="connectionFactory" ref="connectionFactory" />
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="prefetchCount" value="10"/>
<property name="defaultRequeueRejected" value="false"/>
</bean>
<rabbit:listener-container connection-factory="connectionFactory" concurrency="5" prefetch="10" acknowledge="auto" idle-event-interval="500000000000000">
<rabbit:listener ref="rabbitListenerContainerFactory" queue-names="queue.email" />
<rabbit:listener ref="rabbitListenerContainerFactory" queue-names="queue.sms" />
</rabbit:listener-container>
我希望在RabbitMq节点停止时不会出现异常
org.springframework.amqp.rabbit.connection.AutoRecoverConnectionNotCurrentlyOpenException: Auto recovery connection is not currently open
at org.springframework.amqp.rabbit.connection.SimpleConnection.isOpen(SimpleConnection.java:95)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$ChannelCachingConnectionProxy.isOpen(CachingConnectionFactory.java:1151)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.getChannel(CachingConnectionFactory.java:420)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.access$1500(CachingConnectionFactory.java:97)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$ChannelCachingConnectionProxy.createChannel(CachingConnectionFactory.java:1084)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1435)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387)
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1114)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1100(SimpleMessageListenerContainer.java:95)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1333)
at java.lang.Thread.run(Thread.java:745)
有人可以帮助我们避免这个问题吗?
答案 0 :(得分:0)
您使用的是哪个版本?
如果您自己配置基础连接工厂,请将autoRecoveryEnabled
设置为false
。
请参阅Configuring the Underlying Client Connection Factory。
注意 4.0.x客户端默认启用自动恢复功能;虽然与此功能兼容,但Spring AMQP有自己的恢复机制,通常不需要客户端恢复功能。建议禁用amqp-client自动恢复,以避免在代理可用时获取
AutoRecoverConnectionNotCurrentlyOpenException
,但连接尚未恢复。您可能会注意到此异常,例如,在RabbitTemplate中配置RetryTemplate时,即使故障转移到群集中的另一个代理也是如此。由于自动恢复连接在计时器上恢复,因此可以使用Spring AMQP的恢复机制更快地恢复连接。 从版本1.7.1开始,除非您明确创建自己的RabbitMQ连接工厂并将其提供给CachingConnectionFactory ,否则Spring AMQP会禁用它。 RabbitConnectionFactoryBean创建的RabbitMQ ConnectionFactory实例默认情况下也会禁用该选项。