Is there any option to set AutomaticRecoveryEnable

2019-07-22 21:08发布

Getting stocked while doing with RabbitMQ using Spring-AMQP.

Just need to get a way to configure AutomaticRecoveryEnabled and NetworkRecoveryInterval using Spring-AMQP. There is a direct option to set these flages if you you developing using native RabbitMQ library. But i didn't find a workaround to do the same using spring

Using RabbitMQ Native library(don't need any help)

factory.setAutomaticRecoveryEnabled(true);
factory.setNetworkRecoveryInterval(10000);

Using Spring-AMPQ(need help)

Like above i didn't find any such method while trying with Spring-AMPQ. This is what i am doing now.

@Bean(name="listener")
public SimpleMessageListenerContainer listenerContainer() 
{
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory());
    container.setQueueNames(env.getProperty("mb.queue"));
    container.setMessageListener(new MessageListenerAdapter(messageListener));
    return container;
}

Any help in this regards is highly appreciable. Thanks in advance.

2条回答
姐就是有狂的资本
2楼-- · 2019-07-22 21:31

Well, CachingConnectionFactory has another costructor to apply a com.rabbitmq.client.ConnectionFactory.

So, it just enough to cofigure the last one as a an additional @Bean with appropriate options and inject it to the CachingConnectionFactory.

查看更多
你好瞎i
3楼-- · 2019-07-22 21:37

Just to clarify; Spring AMQP is NOT compatible with automaticRecoveryEnabled.

It has its own recovery mechanisms and has no awareness of the underlying recovery being performed by the client. This leaves dangling connection(s) and Channel(s).

I am working on a temporary work-around that will make it compatible (but will effectively disable the client recovery of any connections/channels used by Spring AMQP, while leaving the client recovery in place for other users of the same connection factory.

A longer term fix will require a major rewrite of the listener container to utilize the client recovery code instead.

查看更多
登录 后发表回答