spring-integration icon indicating copy to clipboard operation
spring-integration copied to clipboard

TCP Client Connection Factory Improvements

Open garyrussell opened this issue 6 years ago • 7 comments

Add getConnection(String connectionId) so the client can select which connection it wants (if not open, return null).

Also singleUse serves 2 purposes when true

  • tells the CF to hand out a new connection each time getConnection() is called
  • tells the adapters to close the socket when the send/receive is complete (one-way) or after the reply is sent/received (request/reply).

Split this into two flags sharedConnection and closeAfterCompletion.

See https://stackoverflow.com/questions/55404438/programmatically-create-multiple-connections-for-tcpnetclientconnectionfactory/55404817#55404817

garyrussell avatar Mar 28 '19 18:03 garyrussell

Hi @garyrussell , Shall i work on this item ?

deepak5127 avatar Sep 10 '20 21:09 deepak5127

@deepak5127 ,

sure! You can take a crack on this and we together can see what to do else in your Pull Request!

artembilan avatar Sep 10 '20 22:09 artembilan

@artembilan I have couple of questions.

  1. Should i replace singleUse boolean with two boolean flags? Like replace singleUse in AbstractConnectionFactory with two booleans mentioned above ?
  2. If so it have changes in both client and server factory classes. Also if i understand correctly, we need to use sharedConnection in connection factory for creating / re-using the connections and closeAfterCompletion in adapters to close/keep the connections ?
  3. Also new method getConnection(String connectionId) , should we implement for ThreadAffinityClientConnectionFactory and CachingClientConnectionFactory alone ?

deepak5127 avatar Oct 14 '20 22:10 deepak5127

  1. Yes; but we need to keep (and deprecate) the getter and setter for the old flag (and set both).
  2. Correct.
  3. No; it should be implemented by all client factories; the adapters will need a mechanism to decide which connection id to obtain.

This is a non-trivial change (hence it's been on the backlog for a while).

garyrussell avatar Oct 15 '20 17:10 garyrussell

Thanks @garyrussell . Just to make sure I understand correctly. Instead of calling "this.clientConnectionFactory.getConnection() " from adapters, now we should extract the ip_connectionId from message and call this.clientConnectionFactory.getConnection(connectionId).

If the connection is already created , then send that back or create a new one. Also we need to create a Map in AbstractClientConnectionFactory to hold multiple connections, since we dont have that.

deepak5127 avatar Oct 15 '20 17:10 deepak5127

No; it should be optional only; by default use the existing getConnection().

Add a SpEL expression property; something like connectionIdExpression; which, if present, tells us to try to get the existing connection by name and, if not present, fall back to the existing getConnection() - we might also need. to provide an option to throw an exception if the connection doesn't exist already.

In most cases, yes, the expression will be headers[ip_connectionId].

Yes, we'll need a map of connections.

garyrussell avatar Oct 15 '20 17:10 garyrussell

Thanks @garyrussell . I will work on it.

deepak5127 avatar Oct 15 '20 19:10 deepak5127