-
1. Re: programmatic topic creation using core API
ataylor Sep 6, 2011 8:44 AM (in response to gargkshitiz)1 of 1 people found this helpfulThere is no concept of topics in core, just addresses and queues, think of it this way:
A queue is:
address1 -> queue1 -> consumer1, consumer2 etc
where as a topic is
address1 -> queue1 -> consumer1
-> queue2 -> consumer2
-
2. Re: programmatic topic creation using core API
gargkshitiz Sep 6, 2011 9:23 AM (in response to ataylor)Hi Andy,
We are moving from JMS to core. In JMS, we just had tro create a topic and create consumers on them. HornetQ JMS wrapper would have been generating queues for these consumers internally. Now our API is still same and we want to use core API. so clients would not be passing the queueNames (which HornetQ JMS wrapper would have been generating internally). How do I generate queueNames for them as I have to create queues to map to the JMS agnostic HornetQ architecture.
Regards,
Kshitiz
-
3. Re: programmatic topic creation using core API
ataylor Sep 6, 2011 10:02 AM (in response to gargkshitiz)We are moving from JMS to core. In JMS, we just had tro create a topic and create consumers on them. HornetQ JMS wrapper would have been generating queues for these consumers internally. Now our API is still same and we want to use core API. so clients would not be passing the queueNames (which HornetQ JMS wrapper would have been generating internally). How do I generate queueNames for them as I have to create queues to map to the JMS agnostic HornetQ architecture.
Thats really an application issue, you can call them anything you want, its really up to you. Im not sure i see the issue!
-
4. Re: programmatic topic creation using core API
clebert.suconic Sep 6, 2011 4:19 PM (in response to gargkshitiz)1 of 1 people found this helpfulYou can compose your queue names the same way the JMS layer would do. client_id ++ subscription name.
If you had that in your application before, you can just use that to concatenate the queue name. (what will give you the same function)
-
5. Re: programmatic topic creation using core API
gargkshitiz Sep 7, 2011 3:53 AM (in response to gargkshitiz)Based on your suggestions and our current application state, I am now making the queue names as:
private static AtomicLong counter = new AtomicLong();
public <T> String subscribe(String topicName){
.....
.....
String queueName = topicName + "queue" + counter.addAndGet(1);
clientSession.createQueue(topicName, queueName);
return queueName;
}
and returning queueName as the subscriberID. Now when a client wants to publish a message on that topic, I would say
....
messageProducer.send(topicName, message)
....
Should be fine now...
Thanks !
-
6. Re: programmatic topic creation using core API
gargkshitiz Sep 8, 2011 10:53 AM (in response to gargkshitiz)Hi Clebert,
The approach mentioned by me above would not work when clients from multiple JVMs will ask my code to create unique subscriptions as the line private static AtomicLong counter = new AtomicLong(); will initiate the counter as 0 in all those JVMs and this counter will not help me creating unique queue names. So I am stuck again.
Let me explain the real problem:
JMS:
In our application when clients were calling createTopic(topicName) we were creating topics on HornetQ like this: org.hornetq.api.jms.HornetQJMSClient.createTopic(topicName);
When subsribers were coming to subscribe on that topic , they were calling subscribe(topicName, subscriberlistener) and we were doing
javax.jms.MessageConsumer consumer = session.createConsumer(topic);
consumer.setMessageListener(subscriberlistener);
While running the above code, I assume that the hornetQJMS wrapper was creating queues on behalf of the subscribers which were bounded with the address 'topicName'. Those queues created by hornetQ should have been unique even if createTopic and the subscribe were happening from different JVMs. No worries!
Core API:
When clients call createTopic(topicName) , I can not create a topic as I was doing with JMS. However, I will just create a queue named ["dummyQueue"+topicName] to maintain the uniqueness of that address in our application. [I guess HornetQ JMS wrappers would have been doing something similar as well, please let me know if that's not correct]. Now when a subscriber calls subscribe(topicName, subscriberlistener) , this is the time I have to create a queue and bind that queue to the address topicName so that if somebody publishes later on that address (=topicName), it will be pushed to the subscriber's queue. The problem is that I have to generate this unique queueName for that subscriber across multiple JVMs which HornetQJMS wrappers were doing for me in JMS implementation.
I am using singleton instances of ClientSession in each JVM. Is there any property in this object or in any other hornetQ core library objects which is unique for a JVM. I can use that unique property to generate unique queue names when my subscribers are coming from different JVMs.
When you said that I can create queueNames like 'client_id ++ subscription name' , what are these 2 parameters ? will they be unique across JVMs?
Please suggest...
Regards,
Kshitiz Garg
-
7. Re: programmatic topic creation using core API
ataylor Sep 8, 2011 11:03 AM (in response to gargkshitiz)This is really an issue for your application, its up to you how you create the queue name it doesnt really matter as long as its unique. Try and forget about topics and just think about address -> queue -> consumer.
If you are interested in how we create a globally unique name take a look at our source
-
8. Re: programmatic topic creation using core API
gargkshitiz Sep 8, 2011 11:06 AM (in response to ataylor)I have downloaded the source code but not able to build it as there is no build.sh . Can you please point me to the code where HornetQJMS warpper creates that unique name when a consumer is created?
-
9. Re: programmatic topic creation using core API
gargkshitiz Sep 13, 2011 3:13 AM (in response to gargkshitiz)HI,
I used topicName + UUID.randomUUID() to create queue names .
Thanks,
Kshitiz Garg