4 Replies Latest reply on Dec 8, 2014 1:10 AM by ajinkya bambal

    HornetQ JMS Management API  "listMessages" operation not working

    ajinkya bambal Newbie

      I am using JMS Management API to manage HornetQ queues . I am not able to execute "listMessages" operation. My code snippet as follows:

       

       

       

         Queue managementQueue = HornetQJMSClient.createQueue(HornetQStringContstant.MANAGEMENT_QUEUE_NAME);

         // Create a QueueRequestor for the management queue

          QueueRequestor   requestor = new QueueRequestor((QueueSession) session, managementQueue);

          Message m = session.createMessage();

          Message reply = null;

         JMSManagementHelper.putOperationInvocation(m,

                                                          "jms.queue.exampleQueue",

                                                          "listMessages","");

       

        reply = requestor.request(m);

        boolean success = JMSManagementHelper.hasOperationSucceeded(reply);

        Map<String, Object> messageMap  = (Map<String, Object>) JMSManagementHelper.getResult(reply);

        • 1. Re: HornetQ JMS Management API  "listMessages" operation not working
          Justin Bertram Master

          Please provide enough information to actually understand what's happening, e.g.:

          • What version of HornetQ are you using?
          • Do you see any errors on the client or the server?
          • Does "jms.queue.exampleQueue" exist on the server?  If so, how is it defined/deployed?
          • 2. Re: HornetQ JMS Management API  "listMessages" operation not working
            ajinkya bambal Newbie

            Hi Justin ,

             

            Please find answers inline ,

             

            1) I am using standalone HornetQ 2.3.0.Final version .

            2) I dont see any error in server log but in client log following error came ,

             

            Exception occured at listMessages [Ljava.lang.Object; cannot be cast to java.util.Map

            java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.Map

             

            3)I have defined example queue in hornetq-jms.xml as follows :

               <queue name="exampleQueue">

                  <entry name="/queue/exampleQueue"/>

               </queue>

            4) I have also added following Management related configuration in hornetq-configuration.xml ,

             

                a) Added ,

                           <management-address>jms.queue.hornetq.management</management-address>

                      

                b) under <security-settings> tag added ,

                                         <security-setting match="jms.queue.hornetq.management">

                                            <permission type="manage" roles="guest" />

                                        </security-setting>

            5) I also used JMS management API for "messageCount" (returns integer value) ,"removeMesage" (input : jmsMessageID , returns boolean) ,"removeMessages"(returns integer). But all are working fine except "listMessages"(Which ideally should return Map<String,Object> but it is returning Object) .

             

             

            Please let me know if you need more inputs from me.

            • 3. Re: Re: HornetQ JMS Management API  "listMessages" operation not working
              Justin Bertram Master

              Which ideally should return Map<String,Object> but it is returning Object

              These are your fundamental problems:

              • You expect the "listMessages" operation to return a Map<String,Object> when it in fact returns a Map<String,Object>[] (i.e. an array of Map<String,Object>).  See the JavaDoc.
              • You interpret the message from the ClassCastException to indicate that "listMessages" is returning Object when it is in fact return Object[] (i.e. an array of Object).  "[Ljava.lang.Object" means an array of java.lang.Object.

               

              Therefore your code should look something like this:

               

              Object[] results = (Object[]) JMSManagementHelper.getResult(reply);
              
              for (int i = 0; i < results.length; i++)
              {
                 Map<String, Object> result = (Map<String, Object>) results[i];
                 System.out.println("Message: " + result);
              }