Description
Enhancement
For background on this proposed feature, see my Stack Overflow question from 2/1/19. @garyrussell suggested a custom client connection factory, and that's an option my team is considering.
In summary, my team is designing a proxy/load balancer for TCP stream traffic using Spring Integration. We need high-volume, asynchronous 2-way throughput, so collaborating inbound/outbound Channel Adapters are the only option for us. However, it is also a business requirement that we do not inspect/tamper with the payloads.
So, we are looking into the feasibility of mapping Server Factory connections to Client Factory connections, as Gary suggested. Basically, for each incoming client connection to our Server Factory, we would stand up dedicated upstream connections with our Client Factory. That way, we don't need to correlate messages. Instead, we use the connection map to return responses from upstream servers to the proper client. See the diagram below:
Here, when the first client connects (red connection), the Client Factory would open new connections to both upstream servers. It would also update the connection map so that any responses from the upstream servers arriving on those red connections would go back to the corresponding client.
When the second client connects (blue connection), the Client Factory would notice from the ip_connectionId
header that this is a new connection. It would open a new set of connections to the upstream servers, update the connection map, and pass along the request. The response would then be mapped back to Client 2.
Implementation
I've begun to look through the code inside org.springframework.integration.ip.tcp.*
, and my initial thought is that we may want our Client Factory to extend from TcpNetClientConnectionFactory
. That's the class we're currently using, and it already contains logic to build a connection. No need for us to reimplement that.
We would need to add logic to re-call those methods to build new connections when necessary, as well as maintain the connection map.
These are just my initial thoughts, but if the Spring team has any suggestions of their own, they are welcome!
Concerns
My main concern with this is that the number of connections could get out of hand. Say there are 16 upstream servers, and a client opens 16 connections. That would force the Client Factory to (try to) open 256 upstream connections.
Obviously, we need to control this. My initial thought is to have a configurable limit on how many upstream connections to open, per each new client connection. That would give developers a chance to keep a lid on this.
Misc.
We haven't signed the CLA yet, but will do so before submitting any PRs. Just wanted to get this Issue out.