我們使用Spring-AMQP提供的ConnectionListener接口在底層連接上保留一個選項卡。通道創建時自動恢復,心跳設置爲10分鐘(用於某些產品需求)。我的觀察是即使底層rabbitMQ已經死亡,connectionListener.onClose()方法也不會被調用將近10分鐘。通知通道關閉到實現org.springframework.amqp.rabbit.connection.ConnectionListener的類
我們還對API進行健康狀態檢查,並使用connectionListener.isOpen()方法確定連接的狀態。
因爲SimpleConnection類
@Override public boolean isOpen() { return delegate != null && (delegate.isOpen() || this.delegate.getClass().getSimpleName().contains("AutorecoveringConnection")); }
這個代碼塊,並作爲連接是自動恢復總是返回true。因此,Health API在連接終止後不知道連接失敗10分鐘。
是否有任何推薦的方法來通知ConnectionListener的通道關閉,因爲isOpen方法顯然不符合需要?
正在實施ShutDownlistener的路要走嗎?由於我們無法訪問connectionListerner中的頻道,因此無法直接執行connection.addConnectionListerner(this)。從connectionFactory的shutdownCompleted方法可以調用connectionListener上的onClose或任何其他方法來通知它關閉?
還有其他想法嗎?