TCP Client Connection Factory Improvements
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
Hi @garyrussell , Shall i work on this item ?
@deepak5127 ,
sure! You can take a crack on this and we together can see what to do else in your Pull Request!
@artembilan I have couple of questions.
- Should i replace singleUse boolean with two boolean flags? Like replace singleUse in AbstractConnectionFactory with two booleans mentioned above ?
- 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 ?
- Also new method getConnection(String connectionId) , should we implement for ThreadAffinityClientConnectionFactory and CachingClientConnectionFactory alone ?
- Yes; but we need to keep (and deprecate) the getter and setter for the old flag (and set both).
- Correct.
- 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).
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.
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.
Thanks @garyrussell . I will work on it.