Creating new Topics from a client?
Hello everyone, I have already read the documentation but there is one point still unclear to me.
I want to write a messenger on jms basis so that people using clients can chat with each other. There will be topics that single users can subscribe to and direct chat sessions between two users.
So my question is: is it possible to create new topics during runtime that other users can subscribe to? And will these topics stay alive if the creator has closed his connection to the jms provider?
Thanks, Chris
# 1
In theory the answer is yes, you can do it but in practise it may be a bit tricky. It all depends on the Message Broker implementation. If you were to use SUN Message Queue, the topic exists as long as there is a message on it or there is publisher or consumer connected. Once they are gone it gets deleted in 120 seconds (default). It's possible to change that default value but you would need access the the broker itself. Other JMS providers may have implemented it differently.
Hope this helps - Tom
# 2
Thank you Tom.
I am using JBoss as application server and jms provider. I copied the topic description in form of an xml document into its deployment folder. The clients could find this topic via the jndi.lookup. So I could send messages from one client to the other. I did not understand all what was going on behind the scenes but so far it worked quite well.
But now imagine that client A wants to create a new topic. Then client B must get notified that a new topic has been created. And Client B must be able to receive all messages that have been sent to this topic.
Or maybe Client A wants to establish a direct chat connection to Client B.
Is this possible? Or am I totally wrong with jms? Are there better ways to write a messenger for "natural" persons? Because somehow I got the impression that jms was more intended for communication among distributed systems than among real persons.
I hope I expressed myself clearly, English is not my native language as you can see.
Thanks, Chris
# 3
Well lets assume that client A creates a message and a temporary topic/queue. Then sets the message's JMSReplyTo property to the topic/queue recreated in the previous step. Then publishes the message on a topic that both clients know about. Client B picks up the message. Gets the reply address from the message's JMSReplyTo property, create a new message, new temporary topic/queue, sets the JMS ReplyTo property to new created temporary topic/queue and sends the message to the queue/topic it got with the original message. From this point on you can communicate using only temporary queues/topics.
Hope you get the idea - Tom