Manivelpvn
Manivelpvn

Reputation: 13

With TCP FailOverConnectionFactory is there a way to do custom health check and on failure fallback to failover?

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.

Upvotes: 1

Views: 248

Answers (2)

Gary Russell
Gary Russell

Reputation: 174554

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.

Upvotes: 0

Artem Bilan
Artem Bilan

Reputation: 121272

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.

Upvotes: 1

Related Questions