我正在尝试使用Spring功能来处理重试。我的ListenerContainer是这样定义的:
@Bean("myListenerContainer")
public SimpleMessageListenerContainer statusCheckcontainer(ConnectionFactory connectionFactory, @Autowired StatusQueueListenerServiceImpl messageService) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setMicrometerEnabled(false);
container.setConnectionFactory(connectionFactory);
container.setQueueNames(statusCheckQueueName);
container.setListenerId(statusCheckQueueName);
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
container.setAutoStartup(true);
container.setPrefetchCount(6);
container.setConcurrentConsumers(5);
container.setAdviceChain(RetryInterceptorBuilder.stateful().backOffOptions(statusCheckQueueInitialInterval,
statusCheckQueueMultiplier, statusCheckQueueMaxInterval).maxAttempts(3).keyGenerator(generator-> 1).build());
container.setMessageListener(new MessageListenerAdapter( messageService, jsonMessageConverter()));
return container;
}
我在onMessage方法中强制运行一个RuntimeException,我期望的是只有3次重试尝试,但我看到的是消息被重试,直到TTL(3小时后)过期。
有什么想法吗?提前感谢!
1条答案
按热度按时间px9o7tmv1#
您缺少要为该拦截器设置的
MessageRecoverer
:https://docs.spring.io/spring-amqp/docs/current/reference/html/#async-listeners
编辑
有状态重试示例