spring-integration

Handling late replies in Spring Integration


Lets assume the following scenerio:

Caller ->Gateway -> Bridge         -> Aggregator---      
                                                     ===== output
                 -> TCP Connection -> Aggregator--- 

The general situation is if aggregator timeout then I throw error, and caller will catch it and every is good.

But assume if tcp server is down, then as soon as caller calls gateway, it will encounter "Error making tcp connection". Aggregator will timeout after sometime, and that thrown error will throw following exception:

Reply message received but the receiving thread has exited due to the exceptions while sending the request message.

  1. Is there way if there is tcp error, we can disable this aggregator? The issue here is tcp connection factory and its caching client factory runs in separate thread instead of caller thread.

  2. If we can't cancel the aggregator, what is the possible solution other than seeing weird errors on logs?

Thanks.


Solution

  • So, looks like you are sending same message to the aggregator and TCP request in parallel. Since there is no way to check TCP connection before that, there is no way to cancel a first request to that aggregator. Therefore message group has started already before you know that TCP connection is broken.

    As a solution I would suggestion to not throw an error from the aggregator on timeout. Looks like you got a problem there only if no TCP connection.

    Another way is to not throw an exception from TCP part - the aggregator will timeout either way.

    However, the best solution would be to send a message with TCP error to that aggregator to collect it for the group and probably discard such a group instead of throwing exception on timeout.