我有一个Spring Integration 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:这个建议 org.springframework.integration.handler.advice.RequestHandlerRetryAdvice 只能用于MessageHandlers;试图建议方法 &#39; invokeListener&#39;在 &#39; org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer $ 1#39; 被忽略
如何配置此IntegrationFlow
的行为方式与RabbitListener
相同?即让RabbitMQ再次发布消息。