[英]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.