ActiveMQ get queue size without using JMX, JMS

2019-07-14 01:41发布

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.

标签: java activemq
2条回答
做个烂人
2楼-- · 2019-07-14 02:07

Add Statics 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

查看更多
欢心
3楼-- · 2019-07-14 02:12

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.

查看更多
登录 后发表回答