Search code examples
spring-integrationspring-integration-ip

Is it correct way to log the open connections using CachingClientConnectionFactory


I am implementing TCP Client. I am using CachingClientConnectionFactory to create pool of 10 TCP Connections using TcpNetClientConnectionFactory. I am aiming to print connection ids of open-connections. I came across cachingClientConnectionFactory.getOpenConnectionIds()

But it does not print anything. On digging in deeper, I found that neither CachingClientConnectionFactory nor AbstractClientConnectionFactory provide the implementation for getOpenConnectionIds(). In fact, it is implemented in AbstractConnectionFactory. So, it's safe to assume that the method is only applicable to TCP Server?

I am all ears to other suggestion to print connection ids of open connections on client side. For time being, I am leveraging cachingClientConnectionFactory.getActiveCount() to print the number of open/active connections.


Solution

  • Please open an issue on GitHub, referencing this question.

    The method is supported on both client and server connection factories, but the delegating factories (such as the CachingClientConnectionFactory which delegates to a "real" client factory) currently do not support the method.

    One thing you can do to work around it is to add an @EventListener to receive events when connections are opened and closed.

    https://docs.spring.io/spring-integration/docs/current/reference/html/ip.html#tcp-events