如何使用 spring rabbitmq 在不同队列中配置超时、重试或最大尝试次数 [英] how configure timeouts, retries or max-attempts in differents queues with spring rabbitmq
本文介绍了如何使用 spring rabbitmq 在不同队列中配置超时、重试或最大尝试次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为每个队列进行这些设置?我有很重要的队列,所以我需要更多的重试次数,但有一些不太重要的队列,我不想配置重试、尝试等
Is it possible to make these settings for each queue? I have queues that are important so i need a larger number of retries, but have less important queues that I do not want to configure retry, attempt, etc
public Queue newQueue(String name) {
return new Queue(name, durable, exclusive, autoDelete, arguments);
}
我看到在 Queue 类中,可以将参数映射作为最后一个参数传递,但我不知道它是在这里还是通过属性.
I saw that in the Queue class, it is possible to pass an argument map as the last parameter, but I do not know if it would be here, or via properties.
推荐答案
就我而言,我必须创建一个带有重试拦截器的侦听器工厂,在重试拦截器中我设置了最大尝试次数.
In my case I had to create a listener factory with a retry interceptor, in the retry interceptor I set the value for max attempts.
也许适合你:
@Autowired
private ConnectionFactory connectionFactory;
@Autowired
private SomeService someService;
@RabbitListener(id = "queueListener", queues = "queueName",
containerFactory = "listenerContainerFactory")
@RabbitHandler
public void notifyLegacyListener(SomeObject obj) {
someService.doSomething(obj);
}
@Bean
public SimpleRabbitListenerContainerFactory listenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(jsonMessageConverter());
factory.setConcurrentConsumers(3);
factory.setMaxConcurrentConsumers(10);
factory.setAdviceChain(new Advice[] {retries()});
return factory;
}
@Bean
public RetryOperationsInterceptor retries() {
return RetryInterceptorBuilder.stateless().maxAttempts(Queues.QUEUE_LEGACY.getMaxAttempts())
.backOffOptions(1000,
3.0, 10000)
.recoverer(new RejectAndDontRequeueRecoverer()).build();
}
@Bean
public MessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
这篇关于如何使用 spring rabbitmq 在不同队列中配置超时、重试或最大尝试次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文