我有以下spring集成TCP连接:
<int-ip:tcp-connection-factory id="client" type="client" host="..." port="..." single-use="true" so-timeout="10000"/>
我希望能够在发生协议级问题时强制重新连接。可以这样做吗?如何?
我有以下spring集成TCP连接:
<int-ip:tcp-connection-factory id="client" type="client" host="..." port="..." single-use="true" so-timeout="10000"/>
我希望能够在发生协议级问题时强制重新连接。可以这样做吗?如何?
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).