ActiveMQ get queue size without using JMX, JMS

落花浮王杯 提交于 2020-01-04 17:02:04

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/38551846/activemq-get-queue-size-without-using-jmx-jms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!