Reputation: 117
I have two IntegrationFlows defined that both uses this component. One reads from ftp and one read files from disk.
@Bean
public IntegrationFlow csvLineFlowDefinition() {
return IntegrationFlows.from(CHANNEL_NAME)
.filter(String.class, m -> {
// filter to remove column definition csv line
return !m.startsWith("ID");
})
.<String, MyPrettyObject>transform(csvLinePayload -> {
String[] array = csvLinePayload.split(",");
MyPrettyObject myPrettyObject = new MyPrettyObject();
myPrettyObject.setId(array[0]);
myPrettyObject.setType(array[1]);
return myPrettyObject;
})
.<MyPrettyObject, String>route(myPrettyObject -> myPrettyObject.getType(),
routeResult -> routeResult
.channelMapping("AA", "AA_CHANNEL")
.channelMapping("BB", "BB_CHANNEL")
.channelMapping("CC", "CC_CHANNEL"))
.get();
}
I would like these two IntegrationFlows only to fail if something is wrong with reading from ftp or reading files from the disk. They have their own error channel defined. I do not want an error in the transform of a csv line to MyPrettyObject to reach these two IntegrationFlows.
I have thought about dispatching the raw csv lines to a message queue and then i can define a specific error channel on the inbound consumer of this message queue.
However this seems a bit overkill.
I have tried to insert a ExpressionEvaluatingRequestHandlerAdvice for the transformer, but i'm not sure how to use it properly, and the messages does not reach the router or ERROR_CHANNEL_NAME
@Bean
public ExpressionEvaluatingRequestHandlerAdvice csvLineTransformerAdvice() {
ExpressionEvaluatingRequestHandlerAdvice expressionEvaluatingRequestHandlerAdvice = new ExpressionEvaluatingRequestHandlerAdvice();
expressionEvaluatingRequestHandlerAdvice.setFailureChannelName(ERROR_CHANNEL_NAME);
expressionEvaluatingRequestHandlerAdvice.setTrapException(true);
return expressionEvaluatingRequestHandlerAdvice;
}
.<String, MyPrettyObject>transform(csvLinePayload -> {
String[] array = csvLinePayload.split(",");
MyPrettyObject myPrettyObject = new MyPrettyObject();
myPrettyObject.setId(array[0]);
myPrettyObject.setType(array[1]);
return myPrettyObject;
}, t -> t.advice(csvLineTransformerAdvice()))
Upvotes: 1
Views: 94
Reputation: 121262
I'm afraid that "something wrong with reading" doesn't reach the error-channel because there is no message yet to deal with. So, isolating inbound channel adapter from the rest of the flow might not be a good idea. That is pretty normal for any downstream error to be propagated to the error-channel on the inbound channel adapter.
The ExpressionEvaluatingRequestHandlerAdvice
is right way to go, but you should keep in mind that it works only for the transformer
. The downstream flow isn't involved in that advice already.
In case of error the flow stops and it really can't reach the next endpoint because of error. Not sure what is your concerns there...
Upvotes: 1