2 Replies Latest reply on May 5, 2006 12:19 PM by joejack

    How do I get a list of queues at runtime?

    joejack Newbie

      Is there a way to get a list of queues at runtime programatically?

      Also, how do I create queues on the fly? After hours of searching I have only found 1 example, however it did not look like a valid implementation.

      I've seen many other users ask similar questions on this forum but never getting any reply. So, it appears others have the same need as well but are also having difficulty finding this information. I'm starting to think it can't be done. In fact I did see a reply that said it can't be done but I wanted to try to get an answer here anyway. If, in fact, it can't be done on JBoss then I guess Sonic is the way to go.


        • 1. Re: How do I get a list of queues at runtime?
          mskonda Apprentice

          I don't see any reason why you can't get the destination list from JNDI.

          Use the following code:

          private void listQueues() throws NamingException
           ic = new InitialContext();
           cf = (ConnectionFactory) ic.lookup("ConnectionFactory");
           NamingEnumeration ne = ic.list("queue");//or topic
           NameClassPair dn = (NameClassPair)ne.nextElement();
           System.out.println("destination: "+dn.getName());
           Destination queue = (Queue) ic.lookup(dn.getName());

          What I am doing here is fetching the String equivalent of Queues (or Topics) from JNDI in a list and looping through the list.

          For your second question, use temporary queues


          • 2. Re: How do I get a list of queues at runtime?
            joejack Newbie

            Thanks for the reply. I had thought about using JNDI to get a list but was hoping there was a more direct way via the DestinationManager. I'm a little concerned that there is a possibility for JNDI and the DestinationManager to be out of synch at some points. I would sure like to see a reply from JBoss as to what their paradigm is for such a task.

            After looking at this code I have to ask: What is the point of getting a reference to the ConnectionFactory? Is there something behind the scenes that requires it?

            Also, are there any good examples of using TemporaryQueues? I haven't found any JBoss documentation that covers temporary queues...ConnectionFactories and Destinations are very vendor-specific objects.