出现异常时重试 spring 集成 IntegrationFlow
Retry spring integration IntegrationFlow on exception
我有一个 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'
is ignored
如何配置此 IntegrationFlow
使其与 RabbitListener
的行为相同? IE。让 RabbitMQ 再次发布消息。
在适配器的建议链中使用 retry interceptor 而不是 RequestHandlerRetryAdvice
- 如消息所述,这是用于使用端点。
我有一个 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' is ignored
如何配置此 IntegrationFlow
使其与 RabbitListener
的行为相同? IE。让 RabbitMQ 再次发布消息。
在适配器的建议链中使用 retry interceptor 而不是 RequestHandlerRetryAdvice
- 如消息所述,这是用于使用端点。