获取ActiveMQ的队列长度的任何简单方法? [英] Any simple way to get the queue length of an ActiveMQ?

查看:177
本文介绍了获取ActiveMQ的队列长度的任何简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Java获取ActiveMQ中的队列长度(发送到队列的未消耗消息数)?

How to obtain the queue length (number of unconsumed messages sent to queue) in ActiveMQ, using Java?

推荐答案

您必须使用JMX,因为Queue界面不提供此类信息。

You have to use JMX, since the Queue interface does not provide such information.

检索特定队列大小的示例:

Example of retrieving the size of a specific queue:

// connection
String url = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(url));
MBeanServerConnection connection = connector.getMBeanServerConnection();
// get queue size
ObjectName nameConsumers = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=myqueue");
DestinationViewMBean mbView = MBeanServerInvocationHandler.newProxyInstance(connection, nameConsumers, DestinationViewMBean.class, true);
long queueSize = mbView.getQueueSize();

参考: ActiveMQ JMX 所需的MBean

示例:使用JMX API管理ActiveMQ

这篇关于获取ActiveMQ的队列长度的任何简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆