3 Replies Latest reply on Jan 12, 2011 10:04 AM by bodrin b.

    standalone JMS setup without using JNDI

    bodrin b. Newbie

      Hi,

       

      I'm wondering which is the best way to setup hornetq in a standalone app without JNDI where all consumers and producers are using javax.jms API.

       

      I have searched at the documentation and the examples, but it is not clear to me..

       

      I want to be able to create queues on demand at runtime and setup DLA and other properties (AddressSettings) which can not be done via javax.jms.* API.

       

      -Should I use core hornetq API (org.hornetq.api.core.client.ClientSession.createQueue and org.hornetq.api.core.management.QueueControl) or should I use jms hornetq related API - org.hornetq.jms.server.JMSServerManager and org.hornetq.api.jms.management.JMSQueueControl instead?

       

      -Is JMSServerManager always mandatory in this case?

       

      Thanks,

      bodrin

        • 1. Re: standalone JMS setup without using JNDI
          bodrin b. Newbie

           

          FileConfiguration configuration = new FileConfiguration();
          String url =

          // server setup - begin

           

                         FileConfiguration configuration = new FileConfiguration();

                         String url = getClass().getResource("/hornetq-config.xml").toString();

           

                         configuration.setConfigurationUrl(url);

                         configuration.start();

           

                         HornetQServer server = HornetQServers

                              .newHornetQServer(configuration);

           

                         jmsServerManager = new JMSServerManagerImpl(server);

                         jmsServerManager.setContext(null);

                         jmsServerManager.start();

           

          // server setup - end

           

          ...

           

           

               private static JMSQueueControl createJmsQueue(

                    JMSServerManager jmsServerManager, String queueName,

                    AddressSettings settings) {

                    try {

                         if (jmsServerManager.createQueue(false, queueName, null, true)) {

                              LOG.info("Queue [" + queueName + "] created.");

                         } else {

                              throw new RuntimeException("Failed to create Queue ["

                                   + queueName + "]");

                         }

                         if (settings != null) {

                              jmsServerManager.addAddressSettings(ResourceNames.JMS_QUEUE

                                   + queueName, settings);

                         }

           

                         ObjectName on = ObjectNameBuilder.DEFAULT

                              .getJMSQueueObjectName(queueName);

                         JMSQueueControl jmsQueueControl = (JMSQueueControl) MBeanServerInvocationHandler

                              .newProxyInstance(jmsServerManager.getHornetQServer()

                                   .getMBeanServer(), on, JMSQueueControl.class, false);

                         LOG.info("JMSQueueControl[" + queueName + "] MessageCount: "

                              + jmsQueueControl.getMessageCount());

                         LOG.info("JMSQueueControl[" + queueName + "] DeadLetterAddress: "

                              + jmsQueueControl.getDeadLetterAddress());

           

                         return jmsQueueControl;

                    } catch (Exception e) {

                         throw new RuntimeException(e);

                    }

               }

           

           

           

           

          Is this ok?

           

          If I then create a queue (durable) for example this way:

           

          AddressSettings defaultQueueSettings = new AddressSettings(); defaultQueueSettings.setDeadLetterAddress(new SimpleString(DLQ_NAME)); defaultQueueSettings.setMaxSizeBytes(1024 * 1024); // 1 MiB of RAM per queue defaultQueueSettings.setPageSizeBytes(128 * 1024); defaultQueueSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE); defaultQueueSettings.setMaxDeliveryAttempts(3);


          createJmsQueue(jmsServerManager, "test", defaultQueueSettings);       

           

           

           

          I can use it and checking in jmx I see org.hornetq/Adress/Core/jms.queue.test/Attributes/NumberOfBytesPerPage=131072.

           

          But when I restart later without creating the queue again I see a difference in jmx:

           

          org.hornetq/Adress/Core/jms.queue.test/Attributes/NumberOfBytesPerPage=10485760

           

          (in queue info DLA is missing also)

           

          Is this normal? If yes how is one supposed to keep the queue config?

           

          Message was edited by: bodri bodri

          • 2. standalone JMS setup without using JNDI
            bodrin b. Newbie

            So if using embedded hornetq in a standalone app without JNDI the AddressSetting persistance is not supported by hornetq?

            • 3. Re: standalone JMS setup without using JNDI
              bodrin b. Newbie

              Occasionally found this http://community.jboss.org/message/559196?tstart=2 :

               

                                          1.                        16-Jun-2010 15:25                            (in response to Aspi Engineer)                       

                                                              Re: How do you keep hortnetq JMS and User configuration in sync in a HA setup                       

               

              Destinations created through the management console or management API are stored on the bindings folder. (the jms journal). If you use shared or replicated journal, all the destinations created at the live will be placed on the backup.

               

              For manual configuration however, you would have to copy the files manually and keep them in sync.

               

              Wold that be an issue for you guys?

               

              But in my setup destinations configuration seems to not be stored anywhere. Any ideas what could e the problem ?