How to get consumer count using JMX API in ActiveMQ


first, get a connection to a JMX server (assumes localhost, port 9010, no auth)


First you need to start activemq with jmx service. Add below jvm parameters to java opts-

-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9011 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.local.only=false

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi");
      JMXConnector jmxc = JMXConnectorFactory.connect(url);
      MBeanServerConnection conn = jmxc.getMBeanServerConnection();
      ObjectName activeMQ = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
      BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(conn,
          activeMQ, BrokerViewMBean.class, true);
      for (ObjectName name : mbean.getQueues()) {
        QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler
            .newProxyInstance(conn, name, QueueViewMBean.class, true);
        String queueName = queueMbean.getName();
long count = queueMbean.getConsumerCount()
            }


queue monitoring - getEnqueueCount(), getDequeueCount(), getConsumerCount(), etc...  

Comments

Popular posts from this blog

Encrypt MySQL data using AES techniques