2 Replies Latest reply on Aug 15, 2017 3:31 AM by isurumd

    How to programmatically get message count of a Topic on messaging-activemq

    isurumd

      I'm in a process of upgrading Jboss for 4.2.3 GA to wildfly 10

      in 4.2.3 GA i were able get the message count using a TopicMBean. is there a specific MBean in wildfly 10 that will give me the message count and what will be the format of the Object name for topic

       

      my previous code as follow

       

      String objName= "jboss.messaging.destination:service=Topic,name=Student"

      TopicMBean newMBeanProxy = MBeanServerInvocationHandler.newProxyInstance(Connection.getInstance().connect(), new ObjectName(

                objName), TopicMBean.class, false);

      newMBeanProxy .getAllMessageCount();

        • 1. Re: How to programmatically get message count of a Topic on messaging-activemq
          jbertram

          Management beans are available for most Wildfly components.  These MBeans typically mirror what's available via the Wildfly management CLI.  For example, if you had a topic named "myTopic" it would have an MBean at "jboss.as:subsystem=messaging-activemq,server=default,jms-topic=myTopic".

          • 2. Re: How to programmatically get message count of a Topic on messaging-activemq
            isurumd

            Thanks jbertram

             

            i were able to get message count as follow.

             

            had to include jboss-client.jar for class path

             

            <code>

                String host = "localhost";

                int port = 9990;

                String urlString =

                    System.getProperty("jmx.service.url","service:jmx:remote+http://" + host + ":" + port);

                JMXServiceURL serviceURL = new JMXServiceURL(urlString);

                JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);

                MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

                ObjectName activeMQ = new ObjectName("jboss.as:subsystem=messaging-activemq,server=default,jms-queue=ERROR");

                System.out.println(connection.getAttribute(activeMQ, "message-count"));

                jmxConnector.close();

            </code>