如何检查ActiveMQ“经典”队列是否有消费者

问题描述 投票:0回答:1

我在 Spring Boot 中有一个方法,可以连接到 ActiveMQ“经典”5.10.x 服务器并查询可用队列。我需要创建另一个方法来获取该列表并识别其中哪些没有活跃的消费者。你知道有什么方法可以做到这一点吗?我目前使用的是 Java 17 和 Spring Boot 3.0.1。

这里我留下查询可用队列列表的方法作为示例:

public Set<String> getQueues(String url) throws JMSException {
    try {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(url);
        activeMQConnectionFactory.setUserName(BROKER_USERNAME_1);
        activeMQConnectionFactory.setPassword(BROKER_PASSWORD_1);
        ActiveMQConnection connection = (ActiveMQConnection) activeMQConnectionFactory.createConnection();
        connection.start();
        DestinationSource ds = connection.getDestinationSource();
        Set<ActiveMQQueue> queues = ds.getQueues();
        Set<String> q = new HashSet<>();
        queues.stream().forEach(queue -> {
            try {
                q.add(queue.getQueueName());
            } catch (JMSException e) {
                throw new RuntimeException(e);
            }
        });
        connection.close();
        return q;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

我需要监视是否有队列累积消息且未被消耗,因为它们会导致消息传递服务器服务崩溃。它是为了创建警报,而不是解决问题。

java spring-boot activemq
1个回答
0
投票

ActiveMQ 支持管理视图,通过三种方式查看队列上的消费者计数:

  1. 网络控制台
  2. Jolokia RET API
  3. JMX 连接
© www.soinside.com 2019 - 2024. All rights reserved.