1

I have a Tcp FailOverConnectionFactory supplied with two AbstarctClientConnectionFactory. Each AbstarctClientConnectionFactory will connect to different servers.

And Using TcpOutboundGateway for message exchange. Now i want to switch between the AbstarctClientConnectionFactory based on a Custom Health Check supported by the server.

For Example: If the Client sends message 'TEST HEALTH ', then server replies back as 'GOOD' or 'FAIL'. If the reply received is FAIL, then other AbstarctClientConnectionFactory has to be used for upcoming connections.

Please suggest if it is possible through Spring Integration Ip framework.

Manivelpvn
  • 13
  • 2

2 Answers2

1

The logic is like this essentially:

/**
     * Finds a connection from the underlying list of factories. If necessary,
     * each factory is tried; including the current one if we wrap around.
     * This allows for the condition where the current connection is closed,
     * the current factory can serve up a new connection, but all other
     * factories are down.
     * @throws InterruptedException if interrupted.
     */
    private synchronized void findAConnection() throws InterruptedException {
        ...
        while (!success) {
            try {
                this.delegate = nextFactory.getConnection();
            ...
            }
            catch (RuntimeException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(nextFactory + " failed with "
                            + e.toString()
                            + ", trying another");
                }
                ...
            }
        }
    }

So, you probably can override an AbstractClientConnectionFactory.getConnection() for your custom check and throw an exception if server returns FAIL.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • To do that, you would need to register a temporary `TcpListener` with the new connection and wait for the reply. – Gary Russell Apr 22 '20 at 19:57
  • Yes, this might work but adds an overhead for each request to connection will do a health check before it is available for the actual processing. But, it is enough if we do the health check against each of CF at a regular interval say once in 30s. My intention is if the health Check fails then the connection factory has to be stopped(so that FailoverConnectionFactory will not create connections on this factory which may or may not fails) and it has to be started after given time for connection retry. – Manivelpvn Apr 23 '20 at 13:50
  • Well, you don't have any other choice at the moment. Isn't it? – Artem Bilan Apr 23 '20 at 13:52
  • Well, with framework Yes!!! But did a work around and extended the FailOverConnectionFactory and FailoverTcpConnection. And made the currentFactory to available thru getter in the Extended FailOverConnectionFactory. And stopping the factory on HealthCheck Failure and running a Scheduled Task and starting it after given time to validate it. May be not a cleaner way, but meets my business requirement. – Manivelpvn Apr 23 '20 at 13:57
  • OK. Make sense. Let's continue a discussion in the GH issue you have created! – Artem Bilan Apr 23 '20 at 14:00
0

There is nothing like that in the framework; the FailoverClientConnectionFactory simply fails over when the connection can't be established.

We would have to add some mechanism to the factory to "test" the connection after opening it.

I don't think it would be too difficult to do that; feel free to open a new feature issue on GitHub.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179