4 Replies Latest reply on Aug 16, 2013 6:05 AM by Baskaran Senthivel

    how to obtain a JMSServerControl?

    Ming Fai Ma Newbie

      hi,

       

      I'm trying to create a queue dynamically after a HornetQ server is started. My program follows the EmbeddedExample that all messaging functions work fine. With some researches, it seems JMSServerControl is the interface I'm suppose to use for dynamic queue creation and jndi binding. I couldn't find any documentation about how to obtain a JMSServerControl so I tried to do it in my way like the follows:

       

       

      EmbeddedJMS jms; //created in a way following the EmbeddedExample

      JMSConfiguration jmsConfig; //created following the EmbeddedExample

      JMSServerManagerImpl manager = new JMSServerManagerImpl(jms.getHornetQServer(), jmsConfig);

      //JMSServerManagerImpl manager = new JMSServerManagerImpl(hornetQ); //also tried to do it without the jmsConfig

      manager.activated();

      JMSServerControl control = new JMSServerControlImpl(manager)

       

      I think it technically work and the control.createQueue(...) does create a queue as I can see from the log and also the JMX console, but the queue isn't bind properly and any EmbeddedJMS.lookup() call doesn't return the queue that I have created. before I investage future to fix the binding issue, I'd like to ask:

       

      1) is it the proper way to construst a JMSServerControl programmatically? i feel i'm just hacking it with the public constructor. :-) I couldn't find any API to obtain the control.

       

      2) the JMSServerManager has an activation concept. It has to be activated or otherwise it won't do anything. Once again I hacked it by calling the ativated() method but i seriously think it's not the proper way.

       

      p.s. permananet binding is not my concern. i.e. i don't expect the JNDI binding will preserve after the JVM is restarted.

       

      Thanks,

      Mingfai

        • 1. how to obtain a JMSServerControl?
          rhinmass Newbie

              MBeanServer mBeanServer  = ManagementFactory.getPlatformMBeanServer();  

              ObjectName on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();

              MBeanInfo mbi = mBeanServer.getMBeanInfo(on);

              System.out.println(mbi.getClassName());

              MBeanAttributeInfo[] mbas = mbi.getAttributes();

              for (MBeanAttributeInfo mba : mbas)

              {

                System.out.println("attr: " + mba.getName() + " of type " + mba.getType());

              }

             

              MBeanOperationInfo[] mbos = mbi.getOperations();

              for (MBeanOperationInfo mbo : mbos)

              {

               System.out.println("oper: " + mbo.getName() );

               MBeanParameterInfo[] mbps = mbo.getSignature();

               for (MBeanParameterInfo mbp : mbps)

               {

                 System.out.println("  param: " + mbp.getName());

               }

               System.out.println("   returns: " + mbo.getReturnType());

              }

           

          //get attributes on the JMSServerControl

           

          String[] qnames = (String[]) mBeanServer.getAttribute(on, "QueueNames");

           

          //invoke methods on the JMSServerControl

          mBeanServer.invoke(on, "createQueue" ...)

          • 2. how to obtain a JMSServerControl?
            Ming Fai Ma Newbie

            thx Robin. it's a bit too complex to use JMX given that my embedded usage allows me to access the objects directly.

             

            I found a more "civilized" way to use JMSServerControl. EmbeddedJMS has a protected JMSServerManagerImpl member variable and I've extended it to expose the JMSServerManager to obtain the JMSServerManager for creating the JMSServerControl. Previously, I created a different JMSServerManagerImpl so the things won't work.

             

            public class HornetQJMSServer extends EmbeddedJMS{

                  public JMSServerManagerImpl getJMSServerManager(){

                    return this.serverManager;

                }

            }

             

             

            mingfai

            • 3. how to obtain a JMSServerControl?
              Clebert Suconic Master

              If you are Embedded, sure... it's simpler to just use the POJO.

               

              The proxy is for a remote case.

              • 4. Re: how to obtain a JMSServerControl?
                Baskaran Senthivel Newbie

                Hallo Robin,

                 

                i did as you suggested

                 

                MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

                ObjectName on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();

                MBeanInfo mbi = mBeanServer.getMBeanInfo(on);

                 

                 

                i get a error

                javax.management.InstanceNotFoundException: org.hornetq:module=JMS,type=Server

                Can you please suggest me,what i might be missing.

                 

                However i can see that in the management console that the testQueue is started. I am running EAP6.1 and HornetQ is a standard messaging .