Queue Size in Spring AMQP Java client

后端 未结 2 1182
醉梦人生
醉梦人生 2021-02-14 10:13

I am using Spring amqp 1.1 version as my java client. I have a queue which has around 2000 messages. I want to have a service which checks this queue size and and if it is empt

2条回答
  •  轮回少年
    2021-02-14 10:57

    You can use the RabbitAdmin instance to get the details from the queue, as follows:

    @Resource RabbitAdmin admin;
    ...
    protected int getQueueCount(final String name) {
        DeclareOk declareOk = admin.getRabbitTemplate().execute(new ChannelCallback() {
            public DeclareOk doInRabbit(Channel channel) throws Exception {
                return channel.queueDeclarePassive(name);
            }
        });
        return declareOk.getMessageCount();
    }
    

提交回复
热议问题