ActiveMQ 获取消息数据

来源:互联网 发布:口碑和淘宝外卖一样么 编辑:程序博客网 时间:2024/06/12 21:52

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);


step2:获取Queue的数据

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());}


0 0