有任何简单的方法来获取ActiveMQ的队列长度吗?

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

回答:

您必须使用JMX,因为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的队列长度吗? 的全部内容, 来源链接: utcz.com/qa/399739.html

回到顶部