简体   繁体   English

使用 TCP FailOverConnectionFactory 有没有办法进行自定义健康检查和故障回退到故障转移?

[英]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.我有一个 Tcp FailOverConnectionFactory 提供了两个 AbstarctClientConnectionFactory。 Each AbstarctClientConnectionFactory will connect to different servers.每个 AbstarctClientConnectionFactory 将连接到不同的服务器。

And Using TcpOutboundGateway for message exchange.并使用 TcpOutboundGateway 进行消息交换。 Now i want to switch between the AbstarctClientConnectionFactory based on a Custom Health Check supported by the server.现在我想根据服务器支持的自定义健康检查在 AbstarctClientConnectionFactory 之间切换。

For Example: If the Client sends message ' TEST HEALTH ', then server replies back as ' GOOD ' or ' FAIL '.例如:如果客户端发送消息' TEST HEALTH ',则服务器回复为' GOOD '或' FAIL '。 If the reply received is FAIL, then other AbstarctClientConnectionFactory has to be used for upcoming connections.如果收到的回复是 FAIL,那么其他 AbstarctClientConnectionFactory 必须用于即将到来的连接。

Please suggest if it is possible through Spring Integration Ip framework.请建议是否可以通过 Spring 集成 Ip 框架。

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 .因此,您可能可以覆盖AbstractClientConnectionFactory.getConnection()进行自定义检查,并在服务器返回FAIL时抛出异常。

There is nothing like that in the framework;框架中没有类似的东西; the FailoverClientConnectionFactory simply fails over when the connection can't be established. FailoverClientConnectionFactory只是在无法建立连接时进行故障转移。

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.随时在 GitHub 上打开一个新功能问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM