Spring AMQP Java 客户端中的队列大小 [英] Queue Size in Spring AMQP Java client

查看:40
本文介绍了Spring AMQP Java 客户端中的队列大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring amqp 1.1 版本作为我的 java 客户端.我有一个大约有 2000 条消息的队列.我想要一个检查这个队列大小的服务,如果它是空的,它会发送一条消息说所有项目已处理".

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 empty it will send out a message saying " All items processed".

我不知道如何获取当前队列大小?请帮忙

I dont know how to get current queue size ? Please help

我在谷歌上搜索并找到了早期版本 1.0 中存在的一个类RabbitBrokerAdmin".我认为它现在不存在于 1.1 中.

I googled and found a class "RabbitBrokerAdmin" that was present in earlier version 1.0. I think it is not present in 1.1 now.

获取当前队列大小的任何指针?

Any pointers in getting current queue size?

推荐答案

所以我知道这有点晚了,并且已经找到了解决方案,但这是查看队列中消息计数的另一种方法

So I know this is a little late and a solution has already been found but here is another way to look message counts in your queues

此解决方案假定您使用的是 spring rabbitmq 框架,并已在应用程序配置中定义了队列,并定义了以下标签

This solution assumes that you are using the spring rabbitmq framework and have defined your queues in your application config with the following tags defined

<rabbit:queue>
<rabbit:admin>

java类:

public class QueueStatsProcessor {
    @Autowired
    private RabbitAdmin admin;
    @Autowired
    private List<Queue> rabbitQueues;

    public void getCounts(){
        Properties props;
        Integer messageCount;
        for(Queue queue : rabbitQueues){
            props = admin.getQueueProperties(queue.getName());
            messageCount = Integer.parseInt(props.get("QUEUE_MESSAGE_COUNT").toString());
            System.out.println(queue.getName() + " has " + messageCount + " messages");
        }
    }
}

您还可以使用此解决方案来读取附加到队列的当前消费者http://docs.spring.io/spring-amqp/docs/1.2.1.RELEASE/api/org/springframework/amqp/rabbit/core/RabbitAdmin.html#getQueueProperties(java.lang.String)

You can also use this solution to read the current consumers attached to the queue http://docs.spring.io/spring-amqp/docs/1.2.1.RELEASE/api/org/springframework/amqp/rabbit/core/RabbitAdmin.html#getQueueProperties(java.lang.String)

这篇关于Spring AMQP Java 客户端中的队列大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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