首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用RetryInterceptorBuilder.StatefulRetryInterceptorBuilder.stateful()

如何使用RetryInterceptorBuilder.StatefulRetryInterceptorBuilder.stateful()
EN

Stack Overflow用户
提问于 2020-06-18 19:14:41
回答 1查看 547关注 0票数 1

对于有状态重试,我有如下的RabbitMQ配置:

代码语言:javascript
复制
@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侦听器抛出异常时,不会发生重试。下面是我的听众

代码语言:javascript
复制
@RabbitListener(queues = "myQueue")
public void consume(Message<MyDto> msg) throws Exception {
throw new Exception("Test Exception");
} 

我的实现中有什么问题吗?请提个建议。

EN

回答 1

Stack Overflow用户

发布于 2020-06-18 21:33:01

您的@RabbitListener正在使用默认rabbitListenerContainerFactory,而不是您的queueListenerConnectionFactory

如果您不需要默认的,请将您的重命名为rabbitListenerContainerFactory,或者在侦听器上使用containerFactory属性来告诉它使用您的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62448720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档