Reputation: 9411
How do I approach an error handling in Java DSL flows?
Suppose I have a simple flow that writes to Rabbit (or to a database).
@Bean
public IntegrationFlow setupRabbitFlow() {
return IntegrationFlows.from(publishSubscribeChannel)
.handle((p, h) -> rabbitPublishActivator.publishToRabbit(p))
.get();
}
Such an operation may result in an error due to database issues or intermediary connection failure.
How could I enhance flow declaration towards actions taken if some exception happens within the "publishToRabbit" step?
Upvotes: 2
Views: 1463
Reputation: 121262
If you talk about retry and similar, you should take a look into RequestHandlerRetryAdvice.
On the other hand the .handle()
has the second argument - endpoint configurer. There is you can specify .advice()
:
.handle((GenericHandler<?>) (p, h) -> {
throw new RuntimeException("intentional");
}, e -> e.advice(retryAdvice()))
@Bean
public RequestHandlerRetryAdvice retryAdvice() {
RequestHandlerRetryAdvice requestHandlerRetryAdvice = new RequestHandlerRetryAdvice();
requestHandlerRetryAdvice.setRecoveryCallback(new ErrorMessageSendingRecoverer(recoveryChannel()));
return requestHandlerRetryAdvice;
}
Upvotes: 2