ActiveMQ StatisticsPlugin not working with wildcard destinations

45 views Asked by At

I am using the ActiveMQ "Classic" StatisticsPlugin to collect stats for destinations. I have used ActiveMQ.Statistics.Destination.* along with a replyTo header to collect the stats for all the topics. Unfortunately it's not working. It works if I use a named destination, but it's not working if i use wildcard.

            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();

Could you please help me?

2

There are 2 answers

0
Tim Bish On

To my knowledge the statistics broker plugin does not support query type lookup for multiple destination, you need to query each destination you want to collect data on. There are likely several reasons for this one of them being that the resulting message could end up being enormous if the broker has hundreds or thousands of destination and so some work would need to be put into how this would be handled as even if you chunked the results into multiple messages this could result in a broker running an extremely long task to collect this data possibly stalling other broker work.

You would likely be better off using the JMX management APIs to get insight into the broker and its destination as that feature has been much more developed than this simple statistics plugin that was mostly a tool for old STOMP clients to get some broker information.

0
buggy On

I think you have to use > instead of * in your wildcard, i.e. ActiveMQ.Statistics.Destination.>. See official wildcard documentation for details https://activemq.apache.org/components/classic/documentation/wildcards

TLDR: * only matches one level, for example, ActiveMQ.Statistics.Destination.Xyz. However, destination names are a bit more complex, like ActiveMQ.Statistics.Destination.Queue.Xyz. That's why you have to use >, which matches all the paths recursively.

At least this was the case for our project