Question

I have the following spring integration TCP connection:

<int-ip:tcp-connection-factory id="client" type="client" host="..." port="..." single-use="true" so-timeout="10000"/>

I wish to be able to force a reconnect when a protocol-level problem occurs. Can that be done? How?

Was it helpful?

Solution

Given that you have single-use set to true, a socket is only used once per request so "reconnecting on a failure" makes no sense because a new connection will be established for each request anyway.

With single-use="false" (shared connection), if you are using the factory with an <int-ip:output-channel-adapter/> you can set client-mode to true; this will automatically reconnect after a timeout (and you can explicitly re-establish the shared connection by invoking retryConnection() on the adapter. client-mode is not currently supported on the outbound gateway, however. See TCP Adapters and use your browser to find 'client-mode' for more information.

That said, with single-use="false", you can simply call getConnection() on the client factory and it will re-establish the shared connection (but you must not do anything with the connection). Also, don't do this with single-use="true" however, because it will cause a memory leak (unless you close() the connection - which would make no sense - getting a connection just to close it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top