问题
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);
}
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.
回答1:
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.
Maybe works for you:
@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();
}
回答2:
Such things are not properties of the queue, they are properties of a retry advice added to the listener container. Use a different container/advice for each queue. See the Spring AMQP reference manual.
回答3:
I was able change max retries and back-off strategy in configuration like this:
spring:
rabbitmq:
listener:
simple:
retry:
enabled: true
initial-interval: 1000
max-attempts: 3
max-interval: 10000
multiplier: 2.0
Messages that are still failing will be discarded with a warning with this config. See this article for configuring dead letter queue
来源:https://stackoverflow.com/questions/45385119/how-configure-timeouts-retries-or-max-attempts-in-differents-queues-with-spring