Here is my code get info via jmx, from this code, I can get some info about ActiveMQ like queue name, consumer count, but I don't know how to get consumer list of one queue and get consumer "selector" in the image?
package controller;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
public class Monitor {
public static void main(String[] args) throws Exception {
String url = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
JMXServiceURL urls = new JMXServiceURL(url);
JMXConnector connector = JMXConnectorFactory.connect(urls);
connector.connect();
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
ObjectName objectName = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker");
BrokerViewMBean mBean = MBeanServerInvocationHandler.newProxyInstance(mbsc, objectName, BrokerViewMBean.class, true);
for (ObjectName queueName : mBean.getQueues()) {
QueueViewMBean queueMBean = MBeanServerInvocationHandler.newProxyInstance(mbsc, queueName, QueueViewMBean.class, true);
// queue name
System.out.println("Queue Name:" + queueMBean.getName());
// consumer count
System.out.println("Number of Consumers:" + queueMBean.getConsumerCount());
}
}
}
You can get a list of Consumers (ID) by querying ConnectionViewMBean. You need to pass the connectionName for which you would wish to list all the consumers. To get the connectionName you need to seek help from JCONSOLE. The canonical object name for Connection Object might be somewhat like:
"org.apache.activemq:type=Broker,brokerName=<>,connector=<Connector>,connectorName=<ConnectorName>"
ConnectionViewMBean connectionView = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, <connectionName>, ConnectionViewMBean.class, true);
for (ObjectName name : connectionView.getConsumers()) {
if (name.equals(subscriptionName)) {
found = true;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.