ActiveMQ gets the number of users who listen to a topic from java

I would like to get the number of users listening to a topic from java for the ActiveMQ embedded broker (5.4.2) in the same JVM. Is JMX the only option here? JMX looks like a bad option, as it may be disabled. This post shows how to use JMX to get a list of connections: ActiveMQ: get a list of connections through JMX?

I would prefer a non-JMX based solution, although it might have been disabled because of this. I think JMX will be fine if it is used by java when disconnected. I am just familiar with turning it on / off for use with jconsole.

Am I missing something in the API?

+8
source share
3 answers

You can use Advisory Messages to get the number of queue / topic consumers (among other things) without using JMX (see ActiveMQ.Advisory.Consumer.Topic, etc.) ...

+5
source

I think the number of users in the statistics plugin should give you what you want. And I'm sure that the statistics plugin can be enabled in the built-in broker.

http://activemq.apache.org/statisticsplugin.html

+7
source

In the case of built-in ActiveMQ, you can use BrokerService so that consumers count on the topic. The code is written in Scala, but in Java there shouldn't be much difference.

import org.apache.activemq.broker.{Broker, BrokerService, TransportConnector} val brokerService = new BrokerService() brokerService.setBrokerName("localhost") brokerService.setUseJmx(false) val transportConnector: TransportConnector = brokerServiceSetup.addConnector(s"tcp://localhost:61616") brokerService.start() brokerService.getDestination(new ActiveMQTopic(topicName)) topic.getConsumers 
0
source

All Articles