6 Replies Latest reply on Mar 30, 2012 4:15 AM by snoop.one

    listAllMessages of a JMS queue

    mandarbk

      How can I get the list of all messages for a JMS queue in JBoss 7 ?

       

      Following code snippet throws the exception "javax.management.InstanceNotFoundException: org.hornetq:module=JMS,..........".

       

      ObjectName queueObjectName = new ObjectName("org.hornetq:module=JMS,name=\""+ queueName + "\",type=Queue");

      MBeanServerConnection server = ManagementFactory.getPlatformMBeanServer();

      JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(server,queueObjectName,JMSQueueControl.class,false);            

      return queueControl.countMessages(null);

        • 1. Re: listAllMessages of a JMS queue
          gonne

          Is the jmx management enabled in your hornetq configuration (standalone.xml) ?

           

          CLI command to enable jmx management:

          {code}

          /subsystem=messaging/hornetq-server=default:write-attribute(name=jmx-management-enabled, value=true)

          {code}

          • 2. Re: listAllMessages of a JMS queue
            mandarbk

            Even after enabling JMX , I still get the same exception.

             

            <subsystem xmlns="urn:jboss:domain:messaging:1.1">
                        <hornetq-server>
                            <persistence-enabled>false</persistence-enabled>
                            <jmx-management-enabled>true</jmx-management-enabled>

             

            Exception :

             

            javax.management.InstanceNotFoundException: org.hornetq:module=JMS,name="java:/queue/ProcessQ",type=Queue

            • 3. Re: listAllMessages of a JMS queue
              gonne

              Have you checked the ObjectName of the JMX bean in jconsole or jvisualvm?

              I think your queue name is not correct, the ObjectName should be:

               

              {code}

              org.hornetq:module=JMS,name="ProcessQ",type=Queue

              {code}

              • 4. Re: listAllMessages of a JMS queue
                snoop.one

                I have a similiar problem – and your solution is what I'm looking for.

                But I keep getting

                java.lang.ClassNotFoundException: org.hornetq.api.jms.management.JMSQueueControl

                when deploying my ear. I have the following in my Manifest.mf file,

                 

                Manifest-Version: 1.0

                Dependencies: org.infinispan org.hornetq export

                 

                Thanks in advance

                • 5. Re: listAllMessages of a JMS queue
                  gonne

                  If this is exactly your Manifest file you should separate the dependencies by a comma:

                   

                  {code}

                  Manifest-Version: 1.0

                  Dependencies: org.infinispan, org.hornetq

                  {code}

                   

                  Kind regards,

                  Gonne

                  • 6. Re: listAllMessages of a JMS queue
                    snoop.one

                    Thanks.