Ray Ray - 9 months ago 73
reST (reStructuredText) Question

spring integration throw exception with correlation id

I have a problem with handling batch processing with spring integration.
Normally After splitter, all the element(Message) will be assigned with a correlation_id for future grouping in Aggregator, but the problem is that when there is a exception thrown when processing the element(Message), a MeesageException will be created and the correlation_id is lost.

I can use HeaderEnricher to add the correlation_id but it cannot be hard coded I assume, other wise if there are multiple requests come together, things gonna be grouped together and everything will be messed up.
The root cause is when throwing exception spring integration will not attach the correlation_id... and it seems never be re-gained...

Aggregator will complain about "CorrelationStrategy is failing"

How to deal with this?
Let's say my expectation could be 10 datapoint in batch, and I want to give response for {failed 5, pass 5} or sth


When a org.springframework.messaging.MessagingException is thrown by the Spring Integration components, it is typically contains a failedMessage property to indicate a requestMessage which caused the problem.

All the required headers for you (correlationId, sequenceNumber, sequenceSize etc.) are exactly in that property.

If you are going to send the error-handling result back to the aggregator you should copy headers from that failedMessage to newly created message.

The Framework doesn't do that by default because a ErrorMessage is fully separate flow and there is no guaranty that it always comes back to the main flow, e.g. for aggregation.

See more information in the Error Handling chapter.