0 Replies Latest reply on Sep 6, 2011 12:40 AM by gargkshitiz

    Re: programmatic queue creation

    gargkshitiz

      Hi,

       

      Now it's the turn of topics. I want to create a topic architecture programmatically using core API.

       

      To create a topic , say "hornetQTopic" In JMS, we say:

       

      Topic topic = org.hornetq.api.jms.HornetQJMSClient.createTopic("hornetQTopic")

       

      so we only need a topic name in for a topic creation. And then we create consumers like this:

       

      MessageConsumer messageConsumer = session.createConsumer(topic);

       

      I want to achieve the above using core API. As I understand, there is no need to explicitly create a topic in core API and we can use the 'address' parts in queue creation to create a 'topic' like architecture. So I will NOT create any topic . When the consumer wants to subscribe to a particular topic, say "hornetQTopic" , I will a create a queue on the behalf of that consumer like this:

       

      session.createQueue(getSimpleString("hornetQTopic"), getSimpleString("consumerQueue"), true);

       

      and messages will be published like this:

       

      messageProducer.send(getSimpleString("hornetQTopic"), clientMessage);

       

      In the above method, there is one extra parameter "consumerQueue" to be used as the actual queue name to associate it with the address "hornetQTopic".

       

      The problem is that in JMS, there was no such string needed. My problem is that how do I get this queueName since my consumers won't give this name. Do I have to create an unique string on their behalf like this:

       

      private static AtomicInteger counter = new AtomicInteger();

      public static String createQueueName() {

           return "sub_queue" + counter.addAndGet(1);

      }

       

      Isn't it complicated, is there anything which I am missing here ? I could not find any example of topic architecture using core APIs in the bundled examples.

       

      Regards,

      Kshitiz