8 Replies Latest reply on Jul 8, 2010 2:10 PM by Joe Schmoe

    Management Queue Attributes?

    Joe Schmoe Newbie

      Is there anywhere we can get a list of the valid management queue attributes?  It seems these should be constants somewhere, but I can't for the life of me find them.

       

      Also, it is possible to get the message counters via the management queue in the same way you retrieve them via JMX?  The documentation would suggest that you can.

       

      Here is the code I am using:

       

       

      Queue managementQueue = new HornetQQueue("hornetq.management");
      QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueRequestor requestor = new QueueRequestor(session, managementQueue);
      Message m = session.createMessage();
      //JMSManagementHelper.putAttribute(m, "jms.queue.myQueue", "MessageCount");
      JMSManagementHelper.putAttribute(m, "jms.queue.myQueue", "ListMessageCounter");
      Message reply = requestor.request(m);
      //int messageCount = (Integer) JMSManagementHelper.getResult(reply);
      String counters = (String) JMSManagementHelper.getResult(reply);
      //System.out.println("jms.queue.toolbarEventQueue contains " + messageCount + " messages");
      MessageCounterInfo counter = MessageCounterInfo.fromJSON(counters);
      System.out.format("%s (sample updated at %s)\n",  counter.getName(), counter.getUdpateTimestamp());
               System.out.format("   %s message(s) added to the queue (since last sample: %s)\n", counter.getCount(), 
                                                                                                  counter.getCountDelta());
               System.out.format("   %s message(s) in the queue (since last sample: %s)\n", counter.getDepth(),
                                                                                            counter.getDepthDelta());
               System.out.format("   last message added at %s\n\n", counter.getLastAddTimestamp());
      
      

       

      And I get the following error message:

       

       

      WARNING: exception while retrieving attribute ListMessageCounter on jms.queue.toolbarEventQueue

      java.lang.IllegalStateException: Problem while retrieving attribute ListMessageCounter

           at org.hornetq.core.server.management.impl.ManagementServiceImpl.getAttribute(ManagementServiceImpl.java:767)

           at org.hornetq.core.server.management.impl.ManagementServiceImpl.handleMessage(ManagementServiceImpl.java:462)

           at org.hornetq.core.server.impl.ServerSessionImpl.handleManagementMessage(ServerSessionImpl.java:1112)

           at org.hornetq.core.server.impl.ServerSessionImpl.send(ServerSessionImpl.java:1001)

           at org.hornetq.core.protocol.core.ServerSessionPacketHandler.handlePacket(ServerSessionPacketHandler.java:461)

           at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:471)

           at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:451)

           at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:412)

       

        • 1. Re: Management Queue Attributes?
          Joe Schmoe Newbie

          Nevermind.  I figured out by looking at the source code that you cannot.  However, I also discovered that with a fairly small source code change, it becomes possible.

           

          Original ManagementServiceImpl.getAttribute:

           

          try
                   {
                      method = resource.getClass().getMethod("get" + upperCaseAttribute, new Class[0]);
                   }
                   catch (NoSuchMethodException nsme)
                   {
                      try
                      {
                         method = resource.getClass().getMethod("is" + upperCaseAttribute, new Class[0]);
                      }
                      catch (NoSuchMethodException nsme2)
                      {
                         throw new IllegalArgumentException("no getter method for " + attribute);
                      }
          
          
          

           

          By changing it to:

           

          try {
                        method = resource.getClass().getMethod("get" + upperCaseAttribute, new Class[0]);
                   } catch (NoSuchMethodException ex){}
                   if (method == null) {
                        try {
                            method = resource.getClass().getMethod("is" + upperCaseAttribute, new Class[0]);
                       } catch (NoSuchMethodException ex){}
                   }
                   if (method == null) {
                        try {
                            method = resource.getClass().getMethod("list" + upperCaseAttribute, new Class[0]);
                       } catch (NoSuchMethodException ex){}
                   }
                   if (method == null) throw new IllegalArgumentException("No method could be found in " + resource.getClass().getName() + " for " + attribute);
          

           

          I am now able to do:

           

          Queue managementQueue = new HornetQQueue("hornetq.management");
                    QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                    QueueRequestor requestor = new QueueRequestor(session, managementQueue);
                    Message m = session.createMessage();
                    //JMSManagementHelper.putAttribute(m, "jms.queue.toolbarEventQueue", "MessageCount");
                    JMSManagementHelper.putAttribute(m, "jms.queue.toolbarEventQueue", "MessageCounter");
                              
                    Message reply = requestor.request(m);
                    //int messageCount = (Integer) JMSManagementHelper.getResult(reply);
                    String counters = (String) JMSManagementHelper.getResult(reply);
                    //System.out.println("jms.queue.toolbarEventQueue contains " + messageCount + " messages");
                    MessageCounterInfo counter = MessageCounterInfo.fromJSON(counters);
                     System.out.format("%s (sample updated at %s)\n",  counter.getName(), counter.getUdpateTimestamp());
                   System.out.format("   %s message(s) added to the queue (since last sample: %s)\n", counter.getCount(), 
                                                                                                      counter.getCountDelta());
                   System.out.format("   %s message(s) in the queue (since last sample: %s)\n", counter.getDepth(),
                                                                                                counter.getDepthDelta());
                   System.out.format("   last message added at %s\n\n", counter.getLastAddTimestamp());
          

           

          Any possibility we can get this added to trunk? =)

          • 2. Re: Management Queue Attributes?
            Clebert Suconic Master

            Possibly :-)

             

            I would like to have Jeff Mesnil looking at it first as he did most of the work with management. (Possibly on monday now)

            • 3. Re: Management Queue Attributes?
              Joe Schmoe Newbie

              Awesome, thanks Clebert.  I'll check back. ;-)

              • 4. Re: Management Queue Attributes?
                Tim Fox Master

                All the attributes that can be configured on queues, are done via AddressSettings.

                 

                This is described in the user manual.

                 

                http://hornetq.sourceforge.net/docs/hornetq-2.1.1.Final/user-manual/en/html/queue-attributes.html

                • 5. Re: Management Queue Attributes?
                  Jeff Mesnil Master

                  Caine Lai wrote:

                   

                  Is there anywhere we can get a list of the valid management queue attributes?  It seems these should be constants somewhere, but I can't for the life of me find them.

                  The JMSQueueControl interface defines all the available management attributes and operations on a JMS Queue:

                  http://hornetq.sourceforge.net/docs/hornetq-2.1.1.Final/user-manual/en/html/management.html#d0e6022

                  http://hornetq.sourceforge.net/docs/hornetq-2.1.1.Final/api/org/hornetq/api/jms/management/JMSQueueControl.html

                   

                  Caine Lai wrote:

                   

                  Also, it is possible to get the message counters via the management queue in the same way you retrieve them via JMX?  The documentation would suggest that you can.

                   

                  //JMSManagementHelper.putAttribute(m, "jms.queue.myQueue", "MessageCount"); 
                  JMSManagementHelper.putAttribute(m, "jms.queue.myQueue", "ListMessageCounter");
                    

                  You have to distinguish whethere you want to retrieve a management attribute (using

                  JMSManagementHelper.putAttribute) or invoke a management operation (using JMSManagementHelper.putOperationInvocation):  http://hornetq.sourceforge.net/docs/hornetq-2.1.1.Final/api/org/hornetq/api/jms/management/JMSManagementHelper.html

                   

                  To list message counters you must invoke the operation listMessageCounter() on the JMS Queue Control:

                  JMSManagementHelper.putOperationInvocation(m, "jms.queue.myQueue", "listMessageCounter");

                   

                  The ManagementExample in HornetQ distribution shows how to retrieve an attribute value and invoke a management operation.

                  • 6. Re: Management Queue Attributes?
                    Joe Schmoe Newbie

                    Hi Jeff,

                     

                    Thanks for the response.  However, your code does not work.  It fails with:

                     

                    WARNING: exception while retrieving attribute listMessageCounter on jms.queue.myQueue
                    java.lang.IllegalStateException: Problem while retrieving attribute listMessageCounter
                    at org.hornetq.core.server.management.impl.ManagementServiceImpl.getAttribute(ManagementServiceImpl.java:767)
                    at org.hornetq.core.server.management.impl.ManagementServiceImpl.handleMessage(ManagementServiceImpl.java:462)
                    at org.hornetq.core.server.impl.ServerSessionImpl.handleManagementMessage(ServerSessionImpl.java:1107)
                    at org.hornetq.core.server.impl.ServerSessionImpl.send(ServerSessionImpl.java:996)
                    at org.hornetq.core.protocol.core.ServerSessionPacketHandler.handlePacket(ServerSessionPacketHandler.java:461)
                    at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:471)
                    at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:451)
                    at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:412)
                    at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:459)

                     

                     

                    Again, by looking at the source code in ManagementServiceImpl, it could not possibly work:

                     

                    Method method = null;
                    
                             String upperCaseAttribute = attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
                            try
                             {
                                method = resource.getClass().getMethod("get" + upperCaseAttribute, new Class[0]);
                             }
                             catch (NoSuchMethodException nsme)
                             {
                                try
                                {
                                   method = resource.getClass().getMethod("is" + upperCaseAttribute, new Class[0]);
                                }
                                catch (NoSuchMethodException nsme2)
                                {
                                   throw new IllegalArgumentException("no getter method for " + attribute);
                                }
                             }
                    

                     

                    Which is why I suggested to change it to:

                     

                    Method method = null;
                    
                             String upperCaseAttribute = attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
                    try {
                                  method = resource.getClass().getMethod("get" + upperCaseAttribute, new Class[0]);
                             } catch (NoSuchMethodException ex){}
                             if (method == null) {
                                  try {
                                      method = resource.getClass().getMethod("is" + upperCaseAttribute, new Class[0]);
                                 } catch (NoSuchMethodException ex){}
                             }
                             if (method == null) {
                                  try {
                                      method = resource.getClass().getMethod("list" + upperCaseAttribute, new Class[0]);
                                 } catch (NoSuchMethodException ex){}
                             }
                             if (method == null) throw new IllegalArgumentException("No method could be found in " + resource.getClass().getName() + " for " + attribute);
                    

                     

                    Or better yet,

                     

                    Method method = null;
                             try {
                                  method = resource.getClass().getMethod(attribute, new Class[0]);
                             } catch (NoSuchMethodException ex){
                                  String upperCaseAttribute = attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
                                  try {
                                       method = resource.getClass().getMethod("get" + upperCaseAttribute, new Class[0]);
                                  } catch (NoSuchMethodException ex2){
                                       try {
                                           method = resource.getClass().getMethod("is" + upperCaseAttribute, new Class[0]);
                                      } catch (NoSuchMethodException ex3){
                                           throw new IllegalArgumentException("No method could be found in " + resource.getClass().getName() + " for " + attribute);
                                      }
                                  }
                             }
                    

                     

                    This will allow one to do:

                     

                    JMSManagementHelper.putOperationInvocation(m, "jms.queue.myQueue", "listMessageCounter");

                    • 7. Re: Management Queue Attributes?
                      Jeff Mesnil Master

                      Caine Lai wrote:

                       

                      Hi Jeff,

                       

                      Thanks for the response.  However, your code does not work.  It fails with:

                       

                      WARNING: exception while retrieving attribute listMessageCounter on jms.queue.myQueue
                      java.lang.IllegalStateException: Problem while retrieving attribute listMessageCounter
                      at org.hornetq.core.server.management.impl.ManagementServiceImpl.getAttribute(ManagementServiceImpl.java:767)
                      at org.hornetq.core.server.management.impl.ManagementServiceImpl.handleMessage(ManagementServiceImpl.java:462)

                       

                      The stack trace shows that you are trying to retrieve an attribute named "listMessageCounter". There is no such attribute.

                      As I said in my previous reply, you need to *invoke the operation* using JMSManagementHelper.putOperationInvocation, not JMSManagementHelper.putAttribute.

                       

                      Please double check your client code and if you still have the issue, post it on the forum and I'll have a look at what's going on...

                      • 8. Re: Management Queue Attributes?
                        Joe Schmoe Newbie

                        Ah.  My apologies Jeff, It is all clear to me now.  Thanks for the help.