6 Replies Latest reply on Jun 15, 2011 7:28 PM by Bill Bo

    How to use org.hornetq.api.core.management

    Bill Bo Newbie

      The API itself looks really straightforward.  The problem is, how do you get a handle on a QueueControl or a HornetQServerControl, eg.?

      (Note, not JMS!  The only jars the management code links to are hornetq-core.jar and hornetq-core-client.jar)

        • 2. Re: How to use org.hornetq.api.core.management
          Bill Bo Newbie

          Of course I looked at that (and everything else a search would turn up) before posting this.  That is not asking the same thing.  I am not running anything embedded in anything.  I don't want or need any JMXs or Beans or additional cruft.  Say I just wanted a simple stand alone program to connect to a running server and print the names of all the queues, for example?


          Why is the API so complicated?  You should be able to do something like this:


          connection = Something.get_connection_to_hornetq_server(host, port);

          control = Something.getHornetQServerControl(connection);


          But I cannot find any example code or any explanation in the docs of how to do that (even in a complicated way) just using the core api.  Is that not possible?

          • 3. Re: How to use org.hornetq.api.core.management
            Clebert Suconic Master

            don't want or need any JMXs or Beans or additional cruft.


            Our management API is built in top of JMX.


            Or you could also use JMS as the transport. We have examples on both cases.



            anyway, if you are connected to JBoss, a simple way to get an instance for the HornetQServerControl is:




            public static HornetQServerControl getServerControl(Context ctx) throws Exception {
               RMIAdaptor adaptor = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");
               return MBeanServerInvocationHandler.newProxyInstance(adaptor, ObjectNameBuilder.DEFAULT.getHornetQServerObjectName(), HornetQServerControl.class, false);
            1 of 1 people found this helpful
            • 4. Re: How to use org.hornetq.api.core.management
              Bill Bo Newbie

              Not using JBoss.  Actually I am just running HornetQ inside of Jetty to get the ReST interface, (which so far is working great!).  But then I somehow need to manage this HornetQ instance, hence all these questions. 


              So I cobbled together this sample code from some example code and stuff I read here.  Does this look like it might work or am I missing something?  It scares me that it says "jndi" in there.  I don't think I am using any jndi, but I have no experience with any of this.  I just want the minimal that will get me a connection that can manage the server.


              That is the client side.  Then my next question is, given how I am running HornetQ, how do I enable the jmx port on the server so it will accept this connection?  I assume I'll have to add some kind of acceptor to the configuration file to handle this connection? 


              public class Management {


                  String jmxURL;

                  HornetQServerControl control;


                  public Management(String host, int port) throws Exception {

                      jmxURL = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";



                  public void connect() {

                      JMXConnector connector = JMXConnectorFactory.connect(

                              new JMXServiceURL(jmxUrl), new HashMap());

                      MBeanServerConnection mbsc = connector.getMBeanServerConnection();

                      ObjectName on = ObjectNameBuilder.DEFAULT.getHornetQServerObjectName();

                      control = (HornetQServerControl)MBeanServerInvocationHandler

                              .newProxyInstance(mbsc, on, HornetQServerControl.class, false);



                  public listQueues() {

                      String[] qNames = control.getQueueNames();

                      for (String qName : qNames) {





                  public static void main(String[] args) throws Exception {

                      try {

                          Management mgmt = new Management(args[0], args[1]);



                      } catch (Exception e) {






              • 5. Re: How to use org.hornetq.api.core.management
                Clebert Suconic Master

                if you are just using like the way we inject the JMX:


                   <!-- MBean server -->

                   <bean name="MBeanServer" class="javax.management.MBeanServer">

                      <constructor factoryClass="java.lang.management.ManagementFactory"








                if you are doing that, you just need to follow the examples. If you're doing anything different to inject the MBean, you just need to get access to the MBeanServer anyway it's done on Jetty.

                • 6. Re: How to use org.hornetq.api.core.management
                  Bill Bo Newbie

                  Ok, nevermind.  I just tried running this code and (freaking A) it works!


                  Thanks for all your help!