Search code examples
responsespring-integrationgateway

Spring Integration Async Gateway Response Handling


I need some hint how to solve a problem with Spring Integration.

I have a Gateway interface.

public interface OrderGateway {
   Future<Response> process(Request value);
} 

I send a request message via the gateway. The ValidationService should check if the data is correct. If yes it should forward the message to the OrderService. The OderService will generate a response. But if the request data is not correct the ValidationService should generate a response object return it to the gateway. In that case the OrderService should no be invoked. What kind of message endpoint would be the ValidationService? Would it bit a Router? I would like to a avoid handling this by throwing an exception. How to solve such a situation with Spring Integration?

   +--------------------------------+
   v                                |                         
Async Gateway --> CH --> ValidationService --> CH --> OrderService +
   ^                                                               |
   |---------------------------------------------------------------|                                                                 

Thanks in advance.


Solution

  • The normal way to handle this would be to throw an exception and add an error-channel on the gateway; handle the error there and return the validation response from there.

    If that's not suitable then, yes, a payload type router would work, with the validation result being sent to a "bridge to nowhere" (a bridge with only an input channel) and the framework will route it back to the gateway.