簡體   English   中英

使用 TCP FailOverConnectionFactory 有沒有辦法進行自定義健康檢查和故障回退到故障轉移?

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

我有一個 Tcp FailOverConnectionFactory 提供了兩個 AbstarctClientConnectionFactory。 每個 AbstarctClientConnectionFactory 將連接到不同的服務器。

並使用 TcpOutboundGateway 進行消息交換。 現在我想根據服務器支持的自定義健康檢查在 AbstarctClientConnectionFactory 之間切換。

例如:如果客戶端發送消息' TEST HEALTH ',則服務器回復為' GOOD '或' FAIL '。 如果收到的回復是 FAIL,那么其他 AbstarctClientConnectionFactory 必須用於即將到來的連接。

請建議是否可以通過 Spring 集成 Ip 框架。

邏輯本質上是這樣的:

/**
     * 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");
                }
                ...
            }
        }
    }

因此,您可能可以覆蓋AbstractClientConnectionFactory.getConnection()進行自定義檢查,並在服務器返回FAIL時拋出異常。

框架中沒有類似的東西; FailoverClientConnectionFactory只是在無法建立連接時進行故障轉移。

我們必須在工廠中添加一些機制以在打開連接后“測試”連接。

我認為這樣做不會太難。 隨時在 GitHub 上打開一個新功能問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM