ActiveMQ版本:apache-activemq-5.5.1
1.修改配置文件,开放ActiveMQ的监控功能
step1:修改${ACTIVEMQ_HOME}/conf/activemq.xml
step2:修改启动脚本${ACTIVEMQ_HOME}/bin/activemq,找到下面几行,解除注释
↓
step3:重启服务
2.编写Java代码
step1:连接到activemq的JMX服务
RemoteJMXBrokerFacade createConnector = new RemoteJMXBrokerFacade();
// 填写链接属性
System.setProperty("webconsole.jmx.url","service:jmx:rmi:///jndi/rmi://127.0.0.1:11099/jmxrmi");
System.setProperty("webconsole.jmx.user", "admin");
System.setProperty("webconsole.jmx.password", "activemq");
// 创建配置
SystemPropertiesConfiguration configuration = new SystemPropertiesConfiguration();
// 创建链接
createConnector.setConfiguration(configuration);
Collection<QueueViewMBean> queueViewList = createConnector.getQueues();
for (QueueViewMBean queueViewMBean : queueViewList) {
<span style="white-space:pre"> </span>System.out.println("Queue Name = " + queueViewMBean.getName());
<span style="white-space:pre"> </span>System.out.println("PendingMgs = " + queueViewMBean.getQueueSize());
<span style="white-space:pre"> </span>System.out.println("ConsumerCount = "+ queueViewMBean.getConsumerCount());
<span style="white-space:pre"> </span>System.out.println("DequeueCount = "<span style="white-space:pre"> </span>+ queueViewMBean.getDequeueCount());
<span style="white-space:pre"> </span>System.out.println("EnqueueCount = "<span style="white-space:pre"> </span>+ queueViewMBean.getEnqueueCount());
<span style="white-space:pre"> </span>System.out.println("MemoryPercentUsage = "+ queueViewMBean.getMemoryPercentUsage());
<span style="white-space:pre"> </span>System.out.println("MemoryLimit = " + queueViewMBean.getMemoryLimit());
}