gpt4 book ai didi

java - 出现异常时重试 spring 集成 IntegrationFlow

转载 作者:行者123 更新时间:2023-11-30 06:38:24 27 4
gpt4 key购买 nike

我有一个 spring 集成 IntegrationFlow ,其定义如下:

IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "queueName")
.id("id")
.autoStartup(autoStartup)
.concurrentConsumers(2)
.maxConcurrentConsumers(3)
.messageConverter(messageConverter()))
.aggregate(a -> ...)
.handle(serviceActivatorBean)
.get();

serviceActivatorBean 看起来像这样:

@Component
@Transactional
public class ServiceActivator {

@ServiceActivator

public void myMethod(Collection<MyEvent> events) {
....
}
}

如果myMethod抛出异常,则会记录该异常,但不会发生重试。我尝试将 IntegrationFlow 更改为:

RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
RetryTemplate retryTemplate = new RetryTemplate();
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(5);
retryTemplate.setRetryPolicy(retryPolicy);
advice.setRetryTemplate(retryTemplate);

IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "queueName")
.id("id")
.autoStartup(autoStartup)
.adviceChain(advice)
.concurrentConsumers(2)
.maxConcurrentConsumers(3)
.messageConverter(messageConverter()))
.aggregate(a -> ...)
.handle(serviceActivatorBean)
.get();

但是我收到了这样的日志消息(不会发生重试):

2017-06-30 13:18:10.611 WARN 88706 --- [erContainer#1-2] o.s.i.h.a.RequestHandlerRetryAdvice : This advice org.springframework.integration.handler.advice.RequestHandlerRetryAdvice can only be used for MessageHandlers; an attempt to advise method 'invokeListener' in 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1' is ignored

如何配置此 IntegrationFlow 使其行为与 RabbitListener 相同? IE。让 RabbitMQ 再次发布消息。

最佳答案

使用 retry interceptor在适配器的建议链中,而不是在 RequestHandlerRetryAdvice 中 - 正如消息所述,它用于消费端点。

关于java - 出现异常时重试 spring 集成 IntegrationFlow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44845290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com