Warm tip: This article is reproduced from stackoverflow.com, please click
spring-integration spring-integration-dsl

spring integration dsl error handling and continue

发布于 2020-03-27 10:19:48

In my spring integration application I have Async gateway method that does errorChannel specified.

On Error - I want to handle the error (which I am able to do successfully) by registering an Integration Flow to the errorChannel.

Once the error is Handled and processed, conditionally I might want to send to a different channel for further processing and at the end reply back to the gateway. What is the best way to achieve this?

Example ->

@MessagingGateway(errorChannel = "errorChannel")
public interface OrchestrationServicesGateway {
   @Gateway(requestChannel = "payment.input", replyChannel = 
   "payment.output")
   Future<JobData> processPayment(PaymentRequest request);
}

Integration Flow has step A->B->C->D->end

Now if step B throws an error, I want to handle in a generic function and based on some rules, we might want to continue to C or Jump to D/end.

How do I achieve this ?

Questioner
basu76
Viewed
71
Artem Bilan 2019-07-03 21:53

I would suggest to take a look into an ExpressionEvaluatingRequestHandlerAdvice: https://docs.spring.io/spring-integration/docs/5.1.6.RELEASE/reference/html/#expression-advice. Add it for all your individual endpoints and have there on the failureChannel some router logic to determine where to send compensation message further.

This way you won't have a single error handling point with hard logic to determine where message has been failed.