ActiveMQ 经典统计插件不适用于通配符目的地

问题描述 投票:0回答:3

我正在使用 ActiveMQ Classic StatisticsPlugin 来收集目的地的统计信息。我使用

ActiveMQ.Statistics.Destination.*
replyTo
标题来收集所有主题的统计数据。不幸的是它不起作用。如果我使用命名目的地,它可以工作,但如果我使用通配符,它就不起作用。

            Connection connection = activeMQConnectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            Queue replyTo = session.createTemporaryQueue();
            MessageConsumer consumer = session.createConsumer(replyTo);

            MessageProducer producer = session.createProducer(null);

            // 
            String topicName = "ActiveMQ.Statistics.Destination.*";
            Topic query = session.createTopic(topicName);

            Message msg = session.createMessage();
            msg.setJMSReplyTo(replyTo);
            producer.send(query, msg);
            System.out.println("Message sent to wildcard topics.");

            MapMessage reply = (MapMessage) consumer.receive();
            // assertNotNull(reply);
            System.out.println("test");
            for (Enumeration e = reply.getMapNames(); e.hasMoreElements();) {
                String name = e.nextElement().toString();
                System.out.println(name + "=" + reply.getObject(name));
            }
            connection.close();

你能帮我吗?

activemq-classic amq
3个回答
1
投票

关于“ActiveMQ.Statistics.Destination.>”(或任何 ActiveMQ.Statistics.Destination.XXX>)的响应是多消息。每条回复消息都包含有关一个已找到队列的统计信息。 当请求消息的属性“ActiveMQ.Statistics.Destination.List.End.With.Null”设置为任何非空值时,队列/主题统计列表后的最后一条消息为空。

精彩部分: 发送

Message msg = session.createMessage()
msg.setJMSReplyTo( replyTo)
msg.setStringProperty( "ActiveMQ.Statistics.Destination.List.End.With.Null", 'any value') // the present of key is checked

收到

for(;;) {
  MapMessage reply = (MapMessage) consumer.receive()
  if( !reply.getContent()) {
    break
  }
  for (Enumeration e = reply.getMapNames(); e.hasMoreElements(); ) {
    String name = e.nextElement().toString()
    println( name + "=" + reply.getObject( name))
  }
  print "---\n"
}

更多信息:https://github.com/apache/activemq/blob/main/activemq-broker/src/main/java/org/apache/activemq/plugin/StatisticsBroker.java


0
投票

据我所知,统计代理插件不支持多个目的地的查询类型查找,您需要查询要收集数据的每个目的地。 造成这种情况的原因可能有几个,其中之一是,如果代理有数百或数千个目的地,则生成的消息最终可能会很大,因此需要进行一些工作来处理如何处理该消息,即使您将消息分块结果生成多条消息,这可能会导致代理运行非常长的任务来收集此数据,可能会阻碍其他代理的工作。

您可能最好使用 JMX 管理 API 来深入了解代理及其目的地,因为该功能比这个简单的统计插件要发达得多,该插件主要是旧 STOMP 客户端获取一些代理信息的工具。


0
投票

我认为你必须在通配符中使用

>
而不是
*
,即
ActiveMQ.Statistics.Destination.>
。 有关详细信息,请参阅官方通配符文档https://activemq.apache.org/components/classic/documentation/wildcards

TLDR:

*
仅匹配一级,例如
ActiveMQ.Statistics.Destination.Xyz
。但是,目标名称有点复杂,例如 ActiveMQ.Statistics.Destination.Queue.Xyz。 这就是为什么你必须使用
>
,它递归地匹配所有路径。 至少我们的项目是这样的

© www.soinside.com 2019 - 2024. All rights reserved.