Spring AMQP:将BlockedListener注册为连接 [英] Spring AMQP: Register BlockedListener to Connection

查看:129
本文介绍了Spring AMQP:将BlockedListener注册为连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring AMQP的RabbitTemplate来实现RabbitMQ的阻塞侦听器.在我的代码中,我使用的是Spring-amqp 1.1.3版本的jar文件,而我也已经研究了1.3.1版本,并且在此版本中也不支持.有谁知道我是否缺少支持在RabbitMQ中将阻止的侦听器注册到新连接的任何版本.或者,如果将来有任何春季版本的amqp支持此功能.

I am trying to implement Blocked Listeners to RabbitMQ using RabbitTemplate of Spring AMQP. In my code i am using Spring-amqp 1.1.3 version jar file, whereas i have looked into the version 1.3.1 as well and this is unsupported in this version also. Does anyone know if i am missing any version which has support of registering Blocked listeners to the new connections in RabbitMQ. Or if is there any future release of spring amqp to support this feature.

示例代码:

    Connection connection = factory.newConnection();
    connection.addBlockedListener(new BlockedListener() {
     @Override
     public void handleUnblocked() throws IOException {
        System.out.println("Connection is Unblocked");
     }

     @Override
     public void handleBlocked(String arg0) throws IOException {
        System.out.println("Connection Blocked");
     }           



    });
    com.rabbitmq.client.Channel channel = connection.createChannel();    

推荐答案

当前不可用.请随时打开改善JIRA问题.

This is not currently available out of the box; please feel free to open an Improvement JIRA Issue.

但是,您可以将Spring AMQP ConnectionListener添加到CachingConnectionFactory ...

However, you can add a Spring AMQP ConnectionListener to the CachingConnectionFactory...

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) {

    }

});

即使在添加侦听器时已经建立连接,也会调用它.

It will be called even if the connection has already been established when you add the listener.

这篇关于Spring AMQP:将BlockedListener注册为连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆