简体   繁体   English

ActiveMQ 在不使用 JMX、JMS 的情况下获取队列大小

[英]ActiveMQ get queue size without using JMX, JMS

I need a way for getting queue size in ActiveMQ without using JMX or Iterate all queue using JMS .我需要一种在不使用 JMX使用 JMS 迭代所有队列的情况下在 ActiveMQ 中获取队列大小的方法。 Is there any solution for getting queue size using ActiveMQ API.是否有使用 ActiveMQ API 获取队列大小的解决方案。

There is no API in JMS for querying the broker for stats, that goes against the concept of decoupling the client from each other and the intermediate broker. JMS 中没有用于查询代理以获取统计信息的 API,这违背了将客户端与彼此和中间代理解耦的概念。 ActiveMQ does offer a few things that you can use, JMX being the most powerful way to get what you are after but if you don't want to go directly to the JMX API you can use the REST based approach that makes use of the Jolokia project which ActiveMQ embeds to support access to the JMX Mbeans that the broker exposes using REST calls . ActiveMQ 确实提供了一些您可以使用的东西,JMX 是获得您想要的东西的最强大的方法,但是如果您不想直接使用 JMX API,您可以使用基于 REST 的方法,该方法利用了Jolokia ActiveMQ 嵌入的项目,以支持对代理使用REST 调用公开的JMX Mbean 的访问。

Besides the REST option the only other way is to enable the Statistics Broker Plugin to allow you to send targeted messages to the broker to retrieve run time stats using standard JMS code.除了 REST 选项之外,唯一的另一种方法是启用统计代理插件,以允许您向代理发送目标消息,以使用标准 JMS 代码检索运行时统计信息。

Add Statistics Broker Plugin to your activemq.xml .统计代理插件添加到您的 activemq.xml 。 Following is the code Snippet to fetch ActiveMQ Stats.以下是获取 ActiveMQ 统计信息的代码片段。

public Long checkMessageCountOnAllBroker() throws JMSException {
    MapMessage mapMessage = (MapMessage) jmsTemplate.sendAndReceive("ActiveMQ.Statistics.Broker", Session::createMessage);
    return mapMessage.getLong("size");
}

This will get the size of all the queues from ActiveMq.For getting statics of specific topic.这将从 ActiveMq 获取所有队列的大小。用于获取特定主题的静态信息。

public Long checkMessageCountOnDestination() throws JMSException {
    MapMessage mapMessage = jmsTemplate.sendAndReceive("ActiveMQ.Statistics.Destination.some-topic", Session::createMessage);
    return mapMessage.getLong("size");
}

It will fetch the statistics from the destination topic它将从目标主题中获取统计信息

It is possible to get the queue size from activemq rest api.可以从 activemq rest api 获取队列大小。 A call like the following will return, next to other information for the queue, the queue size.像下面这样的调用将在队列的其他信息旁边返回队列大小。

curl -H "origin: http://localhost" http://activemq:8161/api/jolokia/read/org.apache.activemq:brokerName=localhost,destinationType=Queue,type=Broker,destinationName=<queue-name>

{
    "request": {
        "mbean": "org.apache.activemq:brokerName=localhost,destinationType=Queue,type=Broker,destinationName=<queue-name>",
        "type": "read"
    },
    "value": {
        ...
        "QueueSize": 123,
        ...
    },
    "timestamp": <timestamp>,
    "status": 200
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM