How can I route messages in Spring Integration, which an exception was thrown during processing?

I have the following Integration Flow:

Integration Flow

If an exception is thrown during the second split method, inside the parser, I would like to channel that message to an error channel, is that possible somehow?

Upvotes: 2

Views: 272

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121262

One way is to have an output channel for spitter as an ExecutorChannel or QueueChannel. This way every splitted item is going to be processed in the separate thread. You can then apply any available error handling options for those asyn channels. See docs for more info: https://docs.spring.io/spring-integration/docs/5.2.0.RELEASE/reference/html/error-handling.html#error-handling

Another one is to use a .gateway() with its errorChannel option downstream after the second splitter, so every item is going to be processed in isolation again.

Also an ExpressionEvaluatingRequestHandlerAdvice (maybe together with a RequestHandlerRetryAdvice) can be used downstream on the specific endpoint to deal with its own exceptions: https://docs.spring.io/spring-integration/docs/5.2.0.RELEASE/reference/html/messaging-endpoints.html#message-handler-advice-chain

Upvotes: 3

Related Questions