对于有状态重试,我有如下的RabbitMQ配置:
@Bean
public StatefulRetryOperationsInterceptor statefulRetryOperationsInterceptor(CustomMessageRecoverer customRecoverer) {
StatefulRetryOperationsInterceptor interceptor =
RetryInterceptorBuilder.StatefulRetryInterceptorBuilder.stateful()
.maxAttempts(2)
.recoverer(customRecoverer)
.build();
return interceptor;
}
@Bean
public SimpleRabbitListenerContainerFactory queueListenerConnectionFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory());
factory.setMessageConverter(jsonMessageConverter());
factory.setConcurrentConsumers(this.minConsumersCount);
factory.setMaxConcurrentConsumers(this.maxConsumersCount);
factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
factory.setAdviceChain(statefulRetryOperationsInterceptor(messageRecoverer(rabbitTemplate(connectionFactory()))));
return factory;
}我的邮件头中设置了ID。但是,当Rabbit侦听器抛出异常时,不会发生重试。下面是我的听众
@RabbitListener(queues = "myQueue")
public void consume(Message<MyDto> msg) throws Exception {
throw new Exception("Test Exception");
} 我的实现中有什么问题吗?请提个建议。
发布于 2020-06-18 21:33:01
您的@RabbitListener正在使用默认rabbitListenerContainerFactory,而不是您的queueListenerConnectionFactory。
如果您不需要默认的,请将您的重命名为rabbitListenerContainerFactory,或者在侦听器上使用containerFactory属性来告诉它使用您的。
https://stackoverflow.com/questions/62448720
复制相似问题