10 Replies Latest reply on Mar 23, 2011 7:02 AM by jeanmarie

    Is create queue with JMX a good idea ?

    jeanmarie

      Hi All,

       

      I know there is two way to create queues

      - Manually, with xml files

      - via JMX (Core Api or JMS)

       

      We need durable queues (always available after a restart). I'm not sure about JMX to do this.

      Yes, it's more simple and fast, but is it 100% safe ??

       

       

      Thanks for your help.

        • 1. Is create queue with JMX a good idea ?
          ataylor

          yes its 100% safe as long as you create them as durable

          • 2. Is create queue with JMX a good idea ?
            jeanmarie

            Thanks for your response.

             

            I've created a queue under org.hornetq.Queue.Core, named (Q_TEST_JMS).

             

            Durable=true

             

            But we can't use it from our java code.

             

            HornetQ logs only contains this error :

             

            Connection failure has been detected: Did not receive ping from /x.x.x.x:49589. It is likely the client has exited or crashed without closing its connection, or the network between the server and client has failed. The connection will now be closed. [code=3]

             

            If we try to use a queue created manually, it work.

             

             

            Do you think it's a queue setup problem ?

             

             

            Thanks in advance

            • 3. Re: Is create queue with JMX a good idea ?
              jeanmarie

              ...and this error from the client console

               

              Exception in thread "main" javax.naming.NameNotFoundException: Q_TEST_JMS not bound

              • 4. Is create queue with JMX a good idea ?
                clebert.suconic

                you probably created a core queue, not a JMS queue.

                 

                What object did you use?

                • 5. Is create queue with JMX a good idea ?
                  ataylor

                  take a look at the user manual to see how core queues differe from jms queues, also you could use the jms management api to create the queues instead

                  • 6. Re: Is create queue with JMX a good idea ?
                    jeanmarie

                    Hi,

                     

                     

                    I have tried to create a core queue and a jms queue.

                    In both case, i get

                     

                     

                    Q_xxxxxx  not bound

                     

                     

                    I take a look at the user guide but can't find my trouble at this point...

                     

                     

                    Thanks for your replies

                    • 7. Re: Is create queue with JMX a good idea ?
                      ataylor

                      posting some of your code may help?

                      • 8. Re: Is create queue with JMX a good idea ?
                        jeanmarie

                        Yep. I'm sure you know the author of this example

                         

                         

                        You can take a look at the JMX console when i create the queue.

                        https://picasaweb.google.com/skycoyotte/HORNETQ#5587213166861807410

                         

                         

                         

                        Thanks

                        -----

                        package org.hornetq.jms.example;

                         

                         

                        import java.io.File;

                        import java.io.FileInputStream;

                        import java.util.Properties;

                        import java.util.logging.Logger;

                         

                         

                        import javax.jms.Connection;

                        import javax.jms.ConnectionFactory;

                        import javax.jms.MessageConsumer;

                        import javax.jms.MessageProducer;

                        import javax.jms.Queue;

                        import javax.jms.Session;

                        import javax.jms.TextMessage;

                        import javax.naming.InitialContext;

                         

                         

                        /**

                        * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.

                        *

                        * @author <a href="ataylor@redhat.com">Andy Taylor</a>

                        */

                        public class QueueExample

                        {

                                   protected static Logger log = Logger.getLogger(QueueExample.class.getName());

                         

                         

                         

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

                           {

                              //new QueueExample().run(args);

                                    

                                     QueueExample ex = new QueueExample();

                                     ex.runExample();

                           }

                         

                         

                         

                         

                           public boolean runExample() throws Exception

                           {

                              Connection connection = null;

                              InitialContext initialContext = null;

                              try

                              {

                                 // Step 1. Create an initial context to perform the JNDI lookup.

                                 initialContext = getContext(0);

                         

                         

                                 // Step 2. Perfom a lookup on the queue

                                 Queue queue = (Queue)initialContext.lookup("queue/Q_JMS_TEST");

                         

                         

                                 // Step 3. Perform a lookup on the Connection Factory

                                 ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");

                         

                         

                                 // Step 4.Create a JMS Connection

                                 connection = cf.createConnection();

                         

                         

                                 // Step 5. Create a JMS Session

                                 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                         

                         

                                 // Step 6. Create a JMS Message Producer

                                 MessageProducer producer = session.createProducer(queue);

                         

                         

                                 // Step 7. Create a Text Message

                                 TextMessage message = session.createTextMessage("This is a text message");

                         

                         

                                 System.out.println("Sent message: " + message.getText());

                         

                         

                                 // Step 8. Send the Message

                                 for(int i = 0; i < 1000; i++)

                                           producer.send(message);

                         

                         

                                 // Step 9. Create a JMS Message Consumer

                                 MessageConsumer messageConsumer = session.createConsumer(queue);

                         

                         

                                 // Step 10. Start the Connection

                                 connection.start();

                         

                         

                                 // Step 11. Receive the message

                                 TextMessage messageReceived = null;

                                 while((messageReceived = (TextMessage)messageConsumer.receive(5000)) != null)

                                           System.out.println("Received message: " + messageReceived.getText());

                         

                         

                                 return true;

                              }

                              finally

                              {

                                 // Step 12. Be sure to close our JMS resources!

                                 if (initialContext != null)

                                 {

                                    initialContext.close();

                                 }

                                 if (connection != null)

                                 {

                                    connection.close();

                                 }

                              }

                           }

                           protected InitialContext getContext(final int serverId) throws Exception

                           {

                              String jndiFilename = "server" + serverId + "/client-jndi.properties";

                              File jndiFile = new File(jndiFilename);

                              log.info("using " + jndiFile + " for jndi");

                              Properties props = new Properties();

                              FileInputStream inStream = null;

                              try

                              {

                                 inStream = new FileInputStream(jndiFile);

                                 props.load(inStream);

                              }

                              finally

                              {

                                 if (inStream != null)

                                 {

                                    inStream.close();

                                 }

                              }

                              return new InitialContext(props);

                           }

                         

                         

                        }

                        • 9. Re: Is create queue with JMX a good idea ?
                          ataylor

                          you need to set the jndiBindings as well, this is what the queue will be bound to jndi with

                          • 10. Re: Is create queue with JMX a good idea ?
                            jeanmarie

                            Great ! it works.

                             

                            Now i have to find how can the queue can be used after a service restart. (it's appear under the core section but not under JMS)

                            Answer is probably int the user guide ?

                             

                             

                            Thanks