Reputation: 652
I need a way for getting queue size in ActiveMQ without using JMX or Iterate all queue using JMS. Is there any solution for getting queue size using ActiveMQ API.
Upvotes: 3
Views: 6026
Reputation: 445
It is possible to get the queue size from 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
}
Upvotes: 0
Reputation: 173
Add Statistics Broker Plugin to your activemq.xml . Following is the code Snippet to fetch ActiveMQ Stats.
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.
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
Upvotes: 3
Reputation: 18356
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. 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.
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.
Upvotes: 8