【问题标题】:Retry spring integration IntegrationFlow on exception重试spring集成IntegrationFlow异常
【发布时间】:2017-06-30 11:21:47
【问题描述】:

我有一个 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 警告 88706 --- [erContainer#1-2] o.s.i.h.a.RequestHandlerRetryAdvice :这个建议 org.springframework.integration.handler.advice.RequestHandlerRetryAdvice 只能用于 MessageHandlers;尝试建议方法 'invokeListener' 在 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1' 被忽略

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

【问题讨论】:

    标签: java spring spring-integration spring-amqp spring-integration-amqp


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2018-03-11
      • 2016-08-31
      • 1970-01-01
      相关资源
      最近更新 更多