12 Replies Latest reply on Sep 10, 2009 1:03 PM by clindevall

    How to create persistent queues on the fly

    jbmuser

      Hi Folks,
      The queues I create using JMSServerControlMBean as shown below, are not persistent (i.e. they don't survive a server restart). How could I make it persistent? Please note that I can not use JBM Core API.

      JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap());
      
       MBeanServerConnection mbsc = connector.getMBeanServerConnection();
      
       ObjectName name=new ObjectName("org.jboss.messaging:module=JMS,type=Server");
       JMSServerControlMBean control = (JMSServerControlMBean)MBeanServerInvocationHandler.newProxyInstance(mbsc,name,JMSServerControlMBean.class,false);
       control.createQueue("TestQ","test");


      I understand what the javadoc for session.createQueue() says, i.e. "The physical creation of queues is an administrative task and is not to be initiated by the JMS API". However, I have an exceptional case where I HAVE to create queues dynamically. Other JMS implementations like ActiveMQ and Fiorano supported physical creation of queues through session.createQueue() API but it seems JBM does not support it. Any help is greatly appreciated. I am using JBM 2.0.0.BETA2

      Thanks
      Bijith Kumar

        • 1. Re: How to create persistent queues on the fly
          ataylor

          In JBM2 there are a couple of ways to do this either by using the core API see http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta3/html/using-core.html#d0e1005.

          Alternatively use the management API see http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta3/html/management.html.

          Also beta3 is available which has a couple of performance tweaks.

          • 2. Re: How to create persistent queues on the fly
            jmesnil

            How does the problem occur? Do you have an exception when looking up the queue in JNDI?

            There is a bug in the creation of JMS queue using the management API.
            The underlying core queue is durable and messages will survive server restart but when the server is restarted, the JMS queue is not bound to JNDI and can not be looked up.

            We will fix the bug. In the meantime, a possible workaround for you is to always recreate the queue when the server is restarted using the management API. The 1st time, it will create the queue, the other times, the queue won't be created (it already exists) but the queue will be bound to JNDI again.

            Tell us if this workaround works for you.



            • 3. Re: How to create persistent queues on the fly
              timfox

              I don't agree this is a bug.

              Don't confuse creating queues with *putting queues in JNDI*.

              You can access your queue directly by doing something like:

              JBossQueue queue = new JBossQueue("queue_name");

              you'll find it is there, just like with ActiveMQ.

              • 4. Re: How to create persistent queues on the fly
                jmesnil

                 

                "timfox" wrote:

                You can access your queue directly by doing something like:

                JBossQueue queue = new JBossQueue("queue_name");


                or use JMS API Session.createQueue("foo") (provided the JMS Queue was
                still created first by using the management API)

                • 5. Re: How to create persistent queues on the fly
                  timfox

                   

                  "jmesnil" wrote:

                  or use JMS API Session.createQueue("foo") (provided the JMS Queue was
                  still created first by using the management API)


                  +1

                  • 6. Re: How to create persistent queues on the fly
                    jbmuser

                    Hi Jeff,
                    Thank you for the quick response.
                    I created a queue from JConsole using the operation "createQueue" of MBean "org.jboss.messaging:module=JMS,type=Server" and restarted the server. The queue disappeared after the server restart.
                    My understanding is that, if the queue is really durable and the issue is only with JNDI binding, then I should see the queue from JConsole even after server restart. Please advise.

                    Thanks in advance.
                    Bijith Kumar

                    • 7. Re: How to create persistent queues on the fly
                      peterj

                      You cannot create a persistent queue that way. There are only two ways to create a persistent queue:

                      1 - create a *-service.xml file and declare the queue in it and place the file in the deploy directory

                      2 - use the new admin console (Embedded Jopr)

                      By the way, #2 employs #1 to actually deploy the queue.

                      • 8. Re: How to create persistent queues on the fly
                        clebert.suconic

                         

                        "PeterJ" wrote:
                        You cannot create a persistent queue that way. There are only two ways to create a persistent queue:

                        1 - create a *-service.xml file and declare the queue in it and place the file in the deploy directory

                        2 - use the new admin console (Embedded Jopr)

                        By the way, #2 employs #1 to actually deploy the queue.



                        You realize this thread is about JBossMessaging 2, right?

                        • 9. Re: How to create persistent queues on the fly
                          peterj

                          No, I did not realize this was about JBM 2. Sorry.

                          • 10. Re: How to create persistent queues on the fly
                            clebert.suconic

                             

                            "PeterJ" wrote:
                            No, I did not realize this was about JBM 2. Sorry.


                            No worries.

                            You aways help on the forum... so.. thank you!

                            • 11. Re: How to create persistent queues on the fly
                              jbmuser

                               

                              "jbmuser" wrote:
                              Hi Jeff,
                              Thank you for the quick response.
                              I created a queue from JConsole using the operation "createQueue" of MBean "org.jboss.messaging:module=JMS,type=Server" and restarted the server. The queue disappeared after the server restart.
                              My understanding is that, if the queue is really durable and the issue is only with JNDI binding, then I should see the queue from JConsole even after server restart. Please advise.

                              Thanks in advance.
                              Bijith Kumar


                              "jmesnil" wrote:
                              How does the problem occur? Do you have an exception when looking up the queue in JNDI?

                              There is a bug in the creation of JMS queue using the management API.
                              The underlying core queue is durable and messages will survive server restart but when the server is restarted, the JMS queue is not bound to JNDI and can not be looked up.

                              We will fix the bug. In the meantime, a possible workaround for you is to always recreate the queue when the server is restarted using the management API. The 1st time, it will create the queue, the other times, the queue won't be created (it already exists) but the queue will be bound to JNDI again.

                              Tell us if this workaround works for you.






                              Hi Jeff,
                              Just created a persistent queue successfully using management API. The issue is that, even though the queues survive server restart (i.e. they ARE persistent) but wouldn't show up in JConsole after restart. I am able to obtain the reference of the queue and consume the pending messages even though the queue is not visible in JConsole. It seems the queues become sort of 'invisible' after restart. Btw, I noticed that BETA3 has changed some interfaces in management API. Below given is the new code snippet in case it helps anyone.

                              private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi";
                              JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap());
                              
                               MBeanServerConnection mbsc = connector.getMBeanServerConnection();
                              
                               ObjectName name=new ObjectName("org.jboss.messaging:module=JMS,type=Server");
                               JMSServerControl control = (JMSServerControl)MBeanServerInvocationHandler.newProxyInstance(mbsc,name,JMSServerControl.class,false);
                               control.createQueue("TestQ", "TestQ");


                              Bijith Kumar

                              • 12. Re: How to create persistent queues on the fly
                                clindevall

                                Hi,

                                Is it on the roadmap for HornetQ to extend the JMS dynamic management interface (namely JMSServerControl) with the other createQueue and createTopic versions?

                                Not sure how important this would be for people out there, but I automatically assumed all the versions would be available (or at least one that also includes the selector and temporary parameters).

                                The following fails in the latest version of HornetQ (HornetQ-2.0.0.BETA5):

                                 Queue queue = new HornetQQueue("hornetq.management", "hornetq.management");
                                 QueueRequestor requestor = new QueueRequestor((QueueSession) session, queue);
                                 Message msg = session.createMessage();
                                 JMSManagementHelper.putOperationInvocation(msg, "jms.server",
                                 "createQueue", name, jndi, selector, temporary);
                                 Message reply = requestor.request(msg);
                                 boolean success = JMSManagementHelper.hasOperationSucceeded(reply);
                                


                                I could use "core.server" instead of "jms.server", but then some of the JMS logic is bypassed (eg. binding to JNDI). I'll resort to using "core.server" + calling the JMS logic somehow by hand for now.

                                Decided to post this here, even though it partly does not concern only creation of durable queues and topics.

                                ~CLi