4 Replies Latest reply on Apr 11, 2007 12:57 PM by eee eee

    Number of topic subscriptors

    eee eee Newbie

      Hello, is it possible to get the number of subscritor of a topic?

      Thanks in advance

        • 1. Re: Number of topic subscriptors
          mskonda Apprentice

          You mean subscriptions, right?

          Go to the JNDIView of the relevant Topic and invoke listAllSubscriptions() to get the list of all subscriptions.

          Thanks
          Madhu

          • 2. Re: Number of topic subscriptors
            eee eee Newbie

            Thank you very much, how can i do it programaticly?

            Thanks again...

            • 3. Re: Number of topic subscriptors
              mskonda Apprentice

              Here's the method that would do what you need.

              private void testSubscriptionsList(String destName, String type) throws Exception {
              
               QueueMBean queueMBean = null;
               TopicMBean topicMBean = null;
              
               try {
               //find the mbean server
               mBeanServer = (MBeanServerConnection) new InitialContext().lookup("jmx/invoker/RMIAdaptor");
              
               // create the relevant ON
               // Here type equals to Queue or Topic and
               // destName equals to name of the destination, for example testTopic
              
               serverObjectName = new ObjectName(
               "jboss.messaging.destination:service=" + type + ",name="
               + destName);
              
               // create either queueMBean or topicMBean
               if (type.equalsIgnoreCase("Queue")) {
              
               queueMBean = (QueueMBean) MBeanServerInvocationHandler
               .newProxyInstance(mBeanServer, serverObjectName,
               QueueMBean.class, false);
              
               } else if (type.equalsIgnoreCase("Topic")) {
              
               topicMBean = (TopicMBean) MBeanServerInvocationHandler
               .newProxyInstance(mBeanServer, serverObjectName,
               TopicMBean.class, false);
               }
              
               } catch (NamingException e) {
               logger.warn("NamingException:" + e.getMessage());
               logger.error(e);
               } catch (Exception e) {
               logger.info("Exception:" + e.getMessage());
               logger.error(e);
               }
              
               // once you get the relevant MBean, invoke
               // the appropriate operations.
               // For example, to list the subscription on the topic
               // do this:
               List subs = topicMBean.listAllSubscriptions();
              
               // iterate through the list..
               }


              • 4. Re: Number of topic subscriptors
                eee eee Newbie

                thank you very much...