0

I have an application powered by Spring Integration. in a nutshell the scheme is:

                                             |-> activator
gateWay -> splitter -> transformer -> router |-> ...
                                             |-> activator

For example, service get some json array, split it to json objects, then transforms them to some java object. While transforming it can throw some validation errors.

Spring Integration Reference says:

A Splitter is another type of Message Endpoint whose responsibility is to accept a Message from its input channel, split that Message into multiple Messages, and then send each of those to its output channel.

So I expect, that if I send an json array with one invalid object, which throw validation error, all other messages will be handled normally, and only one invalid object will be pushed to error channel. But it is not. When the first validation exception thrown, all other messages are not handled.

for example: ["correct", "correct", "invalid"] --> 2 messages will be handled, it's ok. ["invalid", "correct", "correct"] --> 0 messages will be handled.

So how to handle messages after splitting, even if there will be errors?

Thanks

m.gavr
  • 83
  • 1
  • 9

1 Answers1

1

Well, that's really not splitter component responsibility to handle downstream errors. It is a mix of responsibility and won't fit to the EIP model.

The same happens when you have a pure Java loop. Right, you can use there try...catch inside the loop, but that doesn't look pretty from the design perspective. So, you decide to move processing logic to the separate method and use that try...catch there. You have just divided a responsibility.

The same we can do, actually, we the splitter and its downstream subscriber for output item. it can be achieved with the ExpressionEvaluatingRequestHandlerAdvice and its onFailureExpression, failureChannel and trapException = true options.

This advice you should use for your transformer definition.

See more information in the Reference Manual. Also there is some clues in the Sample application.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Ok, I see, thanks. I was misled by the description in the documentation _"split that Message into multiple Messages, and then send each of those to its output channel."_ so, i got it as each splitted message has own lifecicle. – m.gavr Feb 27 '18 at 08:11
  • Well, the default Java behavior is assumed. If that is different or with specific meaning we explain it. – Artem Bilan Feb 27 '18 at 13:51