首页 文章

可以处理Spring AMQP Listener Container的java.net.ConnectException吗?

提问于
浏览
1

如果Rabbitmq节点是Down并且我们启动Rabbitmq Listener Container,那么它将循环 infinite Times 直到它连接到Rabbitmq Node.So如果它没有连接到Rabbitmq节点,我们如何能够阻止Listener Container的无限尝试?

1 回答

  • 0

    你需要的是 Listener Container failedEvent,它被发射为;

    private void logException(Throwable t) {
                if (logger.isDebugEnabled()
                        || !(t instanceof AmqpConnectException  || t instanceof CancelledException)) {
                    logger.warn(
                            " raised exception, processing can restart if the connection factory supports it",
                            t);
                }
                else {
                    logger.warn(" raised exception, processing can restart if the connection factory supports it. "
                            + "Exception summary: " + t);
                }
                publishFailedEvent(" raised exception, attempting restart", false, t);
            }
    

    因此,您可以监听这些事件并在达到某些条件时停止您的应用程序 .

相关问题