[英]ActiveMQ get queue size without using JMX, JMS
JMS 中没有用于查询代理以获取统计信息的 API,这违背了将客户端与彼此和中间代理解耦的概念。 ActiveMQ 确实提供了一些您可以使用的东西,JMX 是获得您想要的东西的最强大的方法,但是如果您不想直接使用 JMX API,您可以使用基于 REST 的方法,该方法利用了Jolokia ActiveMQ 嵌入的项目,以支持对代理使用REST 调用公开的JMX Mbean 的访问。
除了 REST 选项之外,唯一的另一种方法是启用统计代理插件,以允许您向代理发送目标消息,以使用标准 JMS 代码检索运行时统计信息。
将统计代理插件添加到您的 activemq.xml 。 以下是获取 ActiveMQ 统计信息的代码片段。
public Long checkMessageCountOnAllBroker() throws JMSException {
MapMessage mapMessage = (MapMessage) jmsTemplate.sendAndReceive("ActiveMQ.Statistics.Broker", Session::createMessage);
return mapMessage.getLong("size");
}
这将从 ActiveMq 获取所有队列的大小。用于获取特定主题的静态信息。
public Long checkMessageCountOnDestination() throws JMSException {
MapMessage mapMessage = jmsTemplate.sendAndReceive("ActiveMQ.Statistics.Destination.some-topic", Session::createMessage);
return mapMessage.getLong("size");
}
它将从目标主题中获取统计信息
可以从 activemq rest api 获取队列大小。 像下面这样的调用将在队列的其他信息旁边返回队列大小。
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.