Reputation: 375
I am processing messages from batch.
Defined advice
for MessageHandler
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setFailureChannelName("errorChannel");
Once there is an error processing one or more messages from they payload, serviceActivator
is triggered
@ServiceActivator(inputChannel = "errorChannel")
public void handleFailure (Message<?> message){
ExpressionEvaluatingRequestHandlerAdvice.MessageHandlingExpressionEvaluatingAdviceException adviceException = (ExpressionEvaluatingRequestHandlerAdvice.MessageHandlingExpressionEvaluatingAdviceException) message.getPayload();
//throw CustomException
So the above gives me the error but not which item from payload caused it (can be more than one).
What is the correct way to retry the payload(one by one)?
Should I somehow 'Split' the payload ? if yes what is the way to do this.
I tried replacing
@ServiceActivator(inputChannel = "errorChannel")
public void handleFailure (Message<?> message){
with
@Splitter(inputChannel = "errorChannel", outputChannel = "outboundChannel")
public List<Message<?>> handleFailure2(Message<?> message)
But couldn't split the messages from there as message's type is ExpressionEvaluatingRequestHandlerAdvice.MessageHandlingExpressionEvaluatingAdviceException
Upvotes: 0
Views: 81
Reputation: 121272
Spring Integration deals with a Message
as a unit of work. It doesn't matter for the framework if payload is a batch of data or not: the service throws an exception, the whole failed message is sent to the error channel with a single exception.
You may consider to use an AggregateMessageDeliveryException
in your service to gather all the errors in a single exception and then throw it for processing in that error handler. There you can inspect such an aggregate to determine what items in batch have been failed.
If you'd like to go a splitter way, then it is going to be a general splitter for your batch and then you process in your service items one by one. Not sure if that is what you'd like to do. However splitter can be configured for an ExecutorChannel
as an output to process items in parallel.
Upvotes: 0