1

How to route the flow from the channel myChannel to the error channel myErrorChannel if there occurs an error in the Http.outboundGateway call?

@Bean
private IntegrationFlow myChannel() {
    return f -> f
            .handle(Http.outboundGateway("http://localhost:8080/greeting")
                    ...
                    .expectedResponseType(String.class));
}

@Bean
private IntegrationFlow myErrorChannel() {
    return f -> f
            ...
}

In the error handler I will wrap the error message inside my custom JSON and I will send that as a part of the normal flow back to the source system.

Is this a good way to handle errors in the Spring Integration Java DSL?

1 Answer 1

1

You can use an ExpressionEvaluatingRequestHandlerAdvice with its returnFailureExpressionResult = true and use it in the second argument of the .handle(..., e -> e.advice(...)).

You configure that advice for the onFailureExpression to be able to return something meaningful. If you still think that you need to send to the channel and get reply back, then you need to have a @MessagingGateway and use it in that onFailureExpression to send and receive. The normal failureChannel configuration in the ExpressionEvaluatingRequestHandlerAdvice doesn't expect reply.

Another approach can be done using the same @MessagingGateway, but in front of that myChannel IntegrationFlow. Then you can configure that gateway for the errorChannel and here a reply from the error flow is expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.