I have a message gateway which is called by a REST controller and I wonder what is the correct approach to handle any errors that might occur on the downstream flow.
What I mean by "handle any errors" is to log some information about them, take some other action whatever that might be, and finally be able to return a 400 to the controller.
For me, the approach that makes more sense is to have an errorChannel on the gateway, BUT I think that a replyChannel might make sense as well.
I've been able to handle the errors with the "errorChannel" approach, don't know if this is the way to go:
@MessagingGateway(errorChannel = "integrationFlowErrorChannel")
public interface OrderGateway {
@Gateway(requestChannel = "orders.input")
void processOrderRequest(Order order);
}
Any error sent to the errorChannel are handle by the following service activator:
@ServiceActivator(inputChannel="integrationFlowErrorChannel")
public void handleExceptions(Message<MessageHandlingException> message) throws RuntimeException {
log.error(String.format("error: %s", message));
log.error(String.format("error: %s", message.getPayload()));
throw new RuntimeException("something bad happened");
}
Thanks