ActiveMQ消息队列获取每个队列中的消费者数、剩余消息数、已消费数、队列名等信息 示例
来源:互联网 发布:java游戏魔幻西游 编辑:程序博客网 时间:2024/04/30 02:26
package util;import org.apache.activemq.broker.jmx.BrokerViewMBean;import org.apache.activemq.broker.jmx.QueueViewMBean;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import javax.management.MBeanServerConnection;import javax.management.MBeanServerInvocationHandler;import javax.management.MalformedObjectNameException;import javax.management.ObjectName;import javax.management.remote.JMXConnector;import javax.management.remote.JMXConnectorFactory;import javax.management.remote.JMXServiceURL;import java.io.IOException;import java.util.HashMap;import java.util.Map;/** * 消息队列工具类 * activemq/conf/activemq.xml文件中 broker节点下,修改managementContext节点内容为 * <managementContext> * <managementContext createConnector="true" connectorPort="1093" connectorPath="/jmxrmi" jmxDomainName="org.apache.activemq"/> *</managementContext> * Created by tianhj on 2016-10-18. */public class ActiveMQUtil { public static final String reportQueueName ="zc-queue-actual";//生成核对报告队列名 private static Log log = LogFactory.getLog(ActiveMQUtil.class); private static final String connectorPort = "1093"; private static final String connectorPath = "/jmxrmi"; private static final String jmxDomain = "org.apache.activemq"; public static Long getQueueSize(String queueName){ Map<String,Long> queueMap=getAllQueueSize(); Long queueSize=0L; if(queueMap.size()>0){ queueSize=queueMap.get(queueName); } return queueSize; } public static Map<String,Long> getAllQueueSize() { Map<String,Long> queueMap=new HashMap<String, Long>(); BrokerViewMBean mBean=null; MBeanServerConnection connection=null; try{ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + connectorPort + connectorPath); JMXConnector connector = JMXConnectorFactory.connect(url); connector.connect(); connection = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(jmxDomain + ":brokerName=localhost,type=Broker"); mBean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true); }catch (IOException e){ log.error("ActiveMQUtil.getAllQueueSize",e); }catch (MalformedObjectNameException e){ log.error("ActiveMQUtil.getAllQueueSize",e); } if(mBean!=null){ for (ObjectName queueName : mBean.getQueues()) { QueueViewMBean queueMBean = MBeanServerInvocationHandler.newProxyInstance(connection, queueName, QueueViewMBean.class, true); queueMap.put(queueMBean.getName(),queueMBean.getQueueSize()); //System.out.println("Queue Name --- " + queueMBean.getName());// 消息队列名称 //System.out.println("Queue Size --- " + queueMBean.getQueueSize());// 队列中剩余的消息数 //System.out.println("Number of Consumers --- " + queueMBean.getConsumerCount());// 消费者数 //System.out.println("Number of Dequeue ---" + queueMBean.getDequeueCount());// 出队数 } } return queueMap; }}
0 1
- ActiveMQ消息队列获取每个队列中的消费者数、剩余消息数、已消费数、队列名等信息 示例
- ActiveMQ发消息、收消息、持久化,查询队列剩余消息数、出队数的实现
- ActiveMQ发消息、收消息、持久化,查询队列剩余消息数、出队数的实现
- ActiveMQ发消息、收消息、持久化,查询队列剩余消息数、出队数的实现
- ActiveMQ 持久化(文件),查询队列剩余消息数、出队数的实现
- ActiveMQ:点对点队列消费者接收不到消息
- ActiveMQ消息队列之java消息生产与消费
- activemq读取剩余消息队列中消息的数量
- ActiveMQ实现消息队列
- ActiveMQ 消息队列
- 队列消息ActiveMq
- 深入浅出 消息队列 ActiveMQ
- 消息队列中间件ActiveMQ
- 深入浅出 消息队列 ActiveMQ
- 深入浅出 消息队列 ActiveMQ
- 深入浅出 消息队列 ActiveMQ .
- 消息队列ActiveMQ
- 深入浅出 消息队列 ActiveMQ
- spi时序
- Codeforces Beta Round #4 (Div. 2 Only) C. Registration system hash
- 华讯成都笔试+面试
- Ecstore官方视频教程
- Rails框架搭建
- ActiveMQ消息队列获取每个队列中的消费者数、剩余消息数、已消费数、队列名等信息 示例
- 【数据结构】C语言实现单链表
- 32个最热CPLD-FPGA论坛
- HDU 5478 Can you find it 随机化 数学
- Ecstore官方视频教程
- 计算字符串中的单词数. 单词:由空格分开的连续字母数字串。
- Python 文件读写操作
- 在亚马逊云服务器上部署阿里数据库Otter(一)
- Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener