Automatic retry connection to broker by spring-rabbitmq

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 11:48:46

That's correct. Spring AMQP manages the re-connection and recovery automatically.

This subject isn't related to bean definitions. If you talk about Broker entities declaration, then yes, that are processed really on the connection establishing.

I've had a similar issue, you just have to put a property on the connection factory configuration.

As per the article here set factory.setAutomaticRecoveryEnabled(true); and factory.setNetworkRecoveryInterval(10000); on the factory and the rabbit client will try to reconnect when the rabbit server is down or the connection is lost.

Because you are using spring configuration for the connection factory your connection factory will be like the following

<bean id="connectionFactory"
      class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    <constructor-arg value="somehost"/>
    <property name="username" value="guest"/>
    <property name="password" value="guest"/>
    <property name="automaticRecoveryEnabled" value="true"/>
    <property name="networkRecoveryInterval" value="100000"/>
</bean>

Connection factory reference here

Yes, the connections will be recreated when the broker is back on line. The default recovery interval is 5 seconds. You can change the recovery interval by setting container.setRecoveryInterval(30000); where container is a SimpleMessageListenerContainer. Setting recovery interval in the underlying connection factory cachingConnectionFactory.getRabbitConnectionFactory().setNetworkRecoveryInterval(int) seems not reflecting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!