14 Replies Latest reply on Jul 4, 2013 10:16 AM by znik

    Core Management Example

    Osian Hughes Newbie



      I am attempting to write a small utility that will tell me the details about what messages are inside the hornetq server, etc. starting simply with a message count of each queue, and then can be extended later for more detailed logging.


      So, I have followed the example within the documentation, but I keep on getting the following error:



      Exception in thread "main" HornetQException[errorCode=105 message=Unable to validate user: null for check type CREATE_NON_DURABLE_QUEUE for address hornetq.management.b4c390ce-5a87-445b-88b9-851e17ab47c9]
                at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:287)
                at org.hornetq.core.client.impl.ClientSessionImpl.internalCreateQueue(ClientSessionImpl.java:1627)
                at org.hornetq.core.client.impl.ClientSessionImpl.createTemporaryQueue(ClientSessionImpl.java:306)
                at org.hornetq.core.client.impl.DelegatingSession.createTemporaryQueue(DelegatingSession.java:306)
                at org.hornetq.api.core.client.ClientRequestor.<init>(ClientRequestor.java:57)
                at org.hornetq.api.core.client.ClientRequestor.<init>(ClientRequestor.java:66)


      And I have a default user setup in my hornetq-users.xml, which is simply the guest, and here is what I've added to my hornetq-configuration.xml file:



          <security-setting match="hornetq.management">
             <permission type="manage" roles="guest" />



      And simply insided the code its:



       private void dumpStats() throws Exception {
                          int count;
                          ClientMessage reply;
                          ClientMessage message;
                          ClientSession clientSession = ...;
                          ClientRequestor requestor = new ClientRequestor(clientSession, "hornetq.management"); //This is the line that blows up
                          for (String queueName : queueNames) {
                                    message = clientSession.createMessage(false);
                        ManagementHelper.putAttribute(message, queueName, "messageCount");
                        reply = requestor.request(message);
                        count = (Integer) ManagementHelper.getResult(reply);
                        System.out.println("# of messages in queue (" + queueName + ") : " + count);



      Note, that I do not have a jms configuration file, because I don't use any JMS, only the core client.


      Any ideas/thoughts are most welcome, and I imagine that it is probably a very simple solution at the end of the day,



        • 1. Core Management Example
          Clebert Suconic Master

          what version?


          what are your secutity settings?

          • 2. Re: Core Management Example
            Osian Hughes Newbie

            The version is 2.1.2.Final


            And my security settings can be seen in the original post, or are there more settings in another file?


            But here is my users configuration:


            <configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
               <!-- the default user.  this is used where username is null-->
               <defaultuser name="guest" password="guest">
                  <role name="guest"/>


            So from this, I would believe that I shouldnt require any security settings within my java code?

            • 3. Re: Core Management Example
              Clebert Suconic Master

              2.1.2 on standalone or jboss?

              • 4. Re: Core Management Example
                Osian Hughes Newbie

                Standalone, no JBoss involved here.

                • 5. Core Management Example
                  Rafael Sánchez Martínez Newbie

                  Note that the problem error consist on preventing you to create a new non durable queue.


                  I would dare to say that HornetQ does not think that hornetq.management is the management address, but its is just trying to create such queue on the fly.

                  • 6. Core Management Example
                    Clebert Suconic Master

                    You still need to create a queue on the management address. you should add create on management address as well.

                    • 7. Core Management Example
                      george pitich Newbie

                      i followed what has been suggested above but to no avail, i must be doing something wrong. I created core queue "queue.hqtest" using core api and it seems to be working fine, producer sends the message and consumer retrieves it. Now i wanted to check the message count in the "queue.hqtest" queue and created "hornetq.management" queue. the code snippet above makes hornetq standalone server throw an exception:


                      [Old I/O server worker (parentId: 5735053, [id: 0x0057828d, ubuntu/])] 12:32:13,232 WARNING [org.hornetq.core.server.management.impl.ManagementServiceImpl]  exception while retrieving attribute messageCount on queue.hqtest

                      java.lang.IllegalStateException: Problem while retrieving attribute messageCount

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

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

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

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

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

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

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

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

                                at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:459)

                                at org.hornetq.core.remoting.impl.netty.HornetQChannelHandler.messageReceived(HornetQChannelHandler.java:73)

                                at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:100)

                                at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)

                                at org.jboss.netty.channel.StaticChannelPipeline$StaticChannelHandlerContext.sendUpstream(StaticChannelPipeline.java:514)

                                at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:287)

                                at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.decode(HornetQFrameDecoder2.java:169)

                                at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.messageReceived(HornetQFrameDecoder2.java:134)

                                at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)

                                at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)

                                at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:357)

                                at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)

                                at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)

                                at org.jboss.netty.channel.socket.oio.OioWorker.run(OioWorker.java:90)

                                at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)

                                at org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)

                                at org.jboss.netty.util.VirtualExecutorService$ChildExecutorRunnable.run(VirtualExecutorService.java:181)

                                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                                at java.lang.Thread.run(Thread.java:619)

                      Caused by: java.lang.IllegalArgumentException: Cannot find resource with name queue.hqtest

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

                                ... 27 more


                      after which i need to restart hq standalone server in order to be able to have producer/consumer run again.


                      I read http://docs.jboss.org/hornetq/2.2.2.Final/user-manual/en/html/management.html#d0e5744 where it states that HornetQServerControl should be used to create/delete queues. i was using ClientSession.createQueue for queue creation. Could that be an issue? Could someone pls advise on how to proceed?


                      Many thanks.

                      • 9. Core Management Example
                        george pitich Newbie

                        hi Rafael,


                        thanks, will have a look. noticed those examples refer to "jms.queue.hornetq.management", may i assume the same approach would work for a core queue? also, my application needs to create (durable) queues during runtime, does this make a difference compared to predefined queues already defined in hornetq-configuration.xml (or hornetq-queues.xml).



                        • 10. Core Management Example
                          Rafael Sánchez Martínez Newbie

                          Good morning George,


                          As an answer to your question one:


                          I read in the manual that naming the management queue as "jms.queue.hornetq.management"is a means to keep compatilibility in the case that you wanted to use it through the JMS API. 


                          In essence, the name is not so important. I have not even tried to try the change the name, because I did not see any actual need to do so. As you can see, the examples in the code above are using the Core API without mattering at all the name.


                          As an answer to the queston two:


                          I guess that creating a queue that way should not make any difference, but honestly, I have not tried such thing yet.


                          Best regards.

                          • 11. Core Management Example
                            Rafael Sánchez Martínez Newbie

                            Good morning, George.


                            The anser to the second question is affirmative. The queues will remain there, even if you shut down the server. However, the server does not update the configuration file for you.


                            You can take a look to



                            The code has also been updated to work with version 2.2.2.

                            • 12. Core Management Example
                              george pitich Newbie

                              Hi Rafael,


                              yes i figured it out myself thankfully to your post at '8 May 22, 2011 5:33 PM' otherwise i would be still pulling my hear


                              the issue was due to ResourceNames.CORE_QUEUE that i missed:


                              ManagementHelper.putAttribute(m, ResourceNames.CORE_QUEUE + queueName, "messageCount");




                              • 14. Re: Core Management Example
                                znik Newbie

                                It seems, counters are not enabled. this is disabled by default because a little performance is degraded.

                                please set line:


                                in hornetq-configuration.xml   file anywhere in section <configuration .... >


                                after this join to the process locally using jconsole from your JRE java version. You find this next to the java.exe or java (system depended) bin directory.

                                look for mbeans tab, and expand tree org.hornetq / Queue / Core / <your defined queue> / <again your defined queue> / attributes  .

                                you should see attribute named MessageCount  , not messageCount  .