Spring 当连接被 RabbitMQ 阻塞时,amqp 没有引发超时异常

Spring amqp is not raising timeout exception when the connection is blocked by RabbitMQ

当RabbitMQ磁盘使用或内存使用达到更高阈值时RabbitMQ将阻塞连接

在 spring amqp 中,每当 rabbitMQ 阻塞连接时,没有关于连接失败的错误消息

有什么方法可以在 spring amqp 中设置发布超时?

提前致谢

阻塞连接监听器在Spring amqp中默认没有启用,我们需要将阻塞连接监听器添加到rabbitmq连接工厂bean以获得阻塞连接通知。

以下代码将起作用:

connectionFactory.addConnectionListener(new ConnectionListener() {

    @Override
    public void onCreate(Connection connection) {
        Channel channel = connection.createChannel(false);
        channel.getConnection().addBlockedListener(new BlockedListener() {
            @Override
            public void handleUnblocked() throws IOException {

            }

            @Override
            public void handleBlocked(String reason) throws IOException {

            }
        });

        try {
            channel.close();
        }
        catch (IOException e) {

        }
    }

    @Override
    public void onClose(Connection connection) {

    }

});

参考

  1. https://www.rabbitmq.com/connection-blocked.html
  2. Spring AMQP: Register BlockedListener to Connection