5 Replies Latest reply on Apr 4, 2007 3:10 AM by exhilarator

    Monitoring the depth of a Queue/Topic

    mbabauer

      As part of a self-impossed excersise to better understand JMS, Spring, JBoss, and how it all fits together, I am writing a little web service that generated hashes off all possible permutations of a string. The way I have things organized currently are as follows:
      1) DAO/VO layer done as a Library that encapulates the generated hashes
      2) Utility layer, deployed as part of the WAR (to be mentioned next) that has a Queue consumer and a Queue producer. The producer is an MBean with a thread that generated possible text permutations, then deposits them into the Queue as a TextMessage. The consumer gets these TextMessages and uses the text to generate the Hashes, create the VOs, and store them into the DB using the DAOs
      3) A WAR thats actually empty, but will eventually be my first Attempt at a real GWT application. Currently its only used to bootstrap Spring and the JBossMQ queue

      As I said, all of this is wired via Spring, and for the JMS Producer I am using the JmsTemplate to send messages.

      My delima now is this. I would like to have the message producer monitor the queue depth in a thread and add messages as it falls below some threashold, sort of like a throttle. Unfortunately, I can't for the life of me figure out how to do this. From the Spring-side, I have access to the JmsTemplate, which means I can get a JMS Connection object or the JMS Destination object. Neither of which seems to have any methods that indicate Queue depth.

      Does anyone out there know where I can start looking? Is there not a generic JMS way to do this? Should I instead start looking to a more JBoss-specific method?

      I was attempting to make this App Server agnostic, but its not really a requirement since I am using JBoss anyway.

        • 1. Re: Monitoring the depth of a Queue/Topic
          genman

          Queue depth cannot be obtained using a standard JMS API. For JBoss MQ there is a JMX interface. For JBoss Messaging there is a compatible JMX interface.

          I don't really see how you could make this app-server agnostic. As an example, SonicMQ has a proprietary API that you can use. ActiveMQ uses JMX.

          • 2. Re: Monitoring the depth of a Queue/Topic
            mbabauer

             

            "genman" wrote:
            I don't really see how you could make this app-server agnostic.

            Well, you got me going in the right direction in any light. It was nice to dream of a world where one J2EE app could coexist peacefully with many an Ap Server.

            • 3. Re: Monitoring the depth of a Queue/Topic
              jurivrljicak

              this way?

              QueueBrowser browser = s.createBrowser(queue);
              int depth= getDepth(browser);

              private int getDepth(QueueBrowser browser) throws JMSException {
              int i=0;
              for(Enumeration e = browser.getEnumeration(); e.hasMoreElements(); ){
              i++;
              e.nextElement();
              }
              return i;
              }

              javax.jms api

              • 4. Re: Monitoring the depth of a Queue/Topic
                timfox

                 

                "jurivrljicak" wrote:
                this way?

                QueueBrowser browser = s.createBrowser(queue);
                int depth= getDepth(browser);

                private int getDepth(QueueBrowser browser) throws JMSException {
                int i=0;
                for(Enumeration e = browser.getEnumeration(); e.hasMoreElements(); ){
                i++;
                e.nextElement();
                }
                return i;
                }

                javax.jms api


                This would probably be horribly slow - I wouldn't recommend it.

                Also browsers are not mandated to provide a static snapshot of the queue, so the result won't necessarily exactly reflect the number of messages in the queue at any particular time.

                • 5. Re: Monitoring the depth of a Queue/Topic
                  exhilarator

                  What is the JMX Interface which is mentioned to achieve this . Is there any way to use this in Spring Framework