ActiveMQ 获取从 Java 收听主题的消费者数量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10291452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:24:45  来源:igfitidea点击:

ActiveMQ get number of consumers listening to a topic from java

javaactivemqjmx

提问by Ryan R.

I would like to be able to get the number of consumers listening to a topic from java for an embedded ActiveMQ (5.4.2) broker in the same JVM. Is JMX really the only option here? JMX seems like a bad option since it may be optionally disabled. This post shows how to use JMX to get a list of connections: ActiveMQ: Get list of connections through JMX?

我希望能够获得在同一 JVM 中为嵌入式 ActiveMQ (5.4.2) 代理从 Java 收听主题的消费者数量。JMX 真的是这里唯一的选择吗?JMX 似乎是一个糟糕的选择,因为它可以被选择性地禁用。这篇文章展示了如何使用 JMX 获取连接列表:ActiveMQ:通过 JMX 获取连接列表?

I would prefer a non-JMX based solution though due to it perhaps being disabled. I guess JMX would be ok if it was still usable from java when disabled. I am just familiar with enabling/disabling it for use with jconsole.

我更喜欢基于非 JMX 的解决方案,因为它可能被禁用。如果 JMX 在禁用时仍然可以从 Java 使用,我想 JMX 就可以了。我只是熟悉启用/禁用它以与 jconsole 一起使用。

Am I missing something in the API?

我在 API 中遗漏了什么吗?

采纳答案by Ben ODay

you can use Advisory Messagesto get the number of consumers of queues/topics (amongst other things) without using JMX (see ActiveMQ.Advisory.Consumer.Topic, etc)...

您可以使用咨询消息来获取队列/主题(除其他外)的消费者数量,而无需使用 JMX(请参阅 ActiveMQ.Advisory.Consumer.Topic 等)...

回答by Jason Axelson

I think that the consumer count in the statistics plugin should give you what you want. And I'm fairly sure that the statistics plugin can be enabled in an embedded broker.

我认为统计插件中的消费者数量应该给你你想要的。而且我相当确定可以在嵌入式代理中启用统计插件。

http://activemq.apache.org/statisticsplugin.html

http://activemq.apache.org/statisticsplugin.html

回答by ?ukasz Gawron

In case of embedded ActiveMQ you may use BrokerService, to get consumers count on topic. Code is in Scala, but there shouldn't be much difference in Java.

在嵌入式 ActiveMQ 的情况下,您可以使用 BrokerService,让消费者依靠主题。代码在 Scala 中,但在 Java 中应该没有太大区别。

            import org.apache.activemq.broker.{BrokerService, TransportConnector}

            val brokerService = new BrokerService()
            brokerService.setBrokerName("localhost")
            brokerService.setUseJmx(false)
            val transportConnector: TransportConnector = brokerServiceSetup.addConnector(s"tcp://localhost:61616")
            brokerService.start()
            brokerService.getDestination(new ActiveMQTopic(topicName))
            topic.getConsumers