4 Replies Latest reply on Jul 27, 2015 10:12 AM by geturner

    Cannot get list of topics using JMX

    geturner

      I current have this code working fully, but I am using a static list of topic names.  I want to get the list from the default server, but I cannot get the correct method name to invoke.  I tried the "read-child-names" but got an error where the bug report said they were not going to open that access up.  So someone please tell me how to do this, it SHOULD be simple!

       

      StringBuilder sb = new StringBuilder("TOPIC_MONITORING\n");

          try {

            MBeanServer server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);

            for (String topicName : topicNames) {

              sb.append(String.format("%35s:", new Object[] { topicName }));

              ObjectName objectName = new ObjectName(new StringBuilder().append("jboss.as:subsystem=messaging,hornetq-server=default,jms-topic=").append(topicName).toString());

              Object subscriptionCount = server.getAttribute(objectName, "subscriptionCount");

              Object messageCount = server.getAttribute(objectName, "messageCount");

              Object messagesAdded = server.getAttribute(objectName, "messagesAdded");

              sb.append(String.format("%20s:%10d", new Object[] { "subscriptionCount", subscriptionCount }));

              sb.append(String.format("%20s:%20d", new Object[] { "messageCount", messageCount }));

              sb.append(String.format("%20s:%20d", new Object[] { "messagesAdded", messagesAdded }));

              sb.append("\n");

            }

          } catch (Exception e) {

            logger.error("error checking topics", e);

          }

          logger.info(sb.toString());

        • 1. Re: Cannot get list of topics using JMX
          mayerw01

          I think the objectName is not correct. You my find the correct names via the java console.

          The method server.getMBeanInfo(objectName) should give you some information about the MBean.

          • 2. Re: Cannot get list of topics using JMX
            geturner

            I assure you, the object names are COMPLETELY correct.  And the MBeanInfo does not provide anything useful.  As I stated, this code works as currently implemented, but I don't like doing this:

             

            private static final String jmxPrefix = "jboss.as:subsystem=messaging,hornetq-server=default,jms-topic=";

            private static final String[] topicNames =

              {

               "AtmosphericParameters",

               "C2SimInput",

               "CalibrationThresholds",

               "CatalogUpdatePCMIn",

               "CatalogUpdateStatusIn",

               "CatalogUpdateRSOIn",

               "Clients",

            • 3. Re: Cannot get list of topics using JMX
              mayerw01

              You could search the objectNames via  queryMBeans:


              ObjectName objectName = new ObjectName("jboss.as.expr:subsystem=messaging,hornetq-server=default,core-address=*");

              Set<ObjectInstance> mbs = server.queryMBeans(objectName, null);


              should give you the objectNames via (ObjectInstance) getObjectName()

              • 4. Re: Cannot get list of topics using JMX
                geturner

                Worked as described, THANK YOU!