Re: NameNotFoundException with temporary topics

"George H" <[email protected]> Mon, 4 Jun 2007 07:25:41 +0300
Newsgroups gmane.comp.java.openjms.user
Message-ID <[email protected]>
On 6/4/07, Tim Anderson <[email protected]> wrote:
> George H wrote:
> > Hi,
> >
> > I'm using OpenJMS 0.7.7-beta-1 configured to use MySQL on a Linux
> > machine. It works fine except when I come to temporary topics.
> >
> > I have 2 java programs; 1 creates a TemporaryTopic and creates a
> > subscriber for it, it also sends the temp topic name to the second
> > java program. The second program receives the name of the temp topic
> > (the one that is auto-generated) and tries to become a publisher for
> > that temp topic.
> >
> > The problem is that the second program get a NameNotFoundException
> > when trying to create a publisher, this happens when I take the
> > topicname and try to treat it like a regular old Topic (creating a
> > session, context, connection .,..etc).
> >
> > I don't see a lot of info on managing temporary topics anywhere. I
> > have several topics which are fixed and have fixed durable
> > subscribers, but I also want clients to communicate temporarily with
> > temp topics...or should I just create and delete regular topics on the
> > fly and generate my own uniqe topic names ?
> >
> > Thanks.
> >
> >
> That's not the correct use of a TemporaryTopic.
> A temporary topic exists for the lifetime of the connection that created
> it, and is used to indicate
> an address to publish replies to. E.g:
>
> // Client
> Topic topic = context.lookup("mytopic");
> Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>
> MessageProducer producer = session.createProducer(topic);
> MessageProducer consumer = session.createConsumer(replyTopic);
>
> // send a request, and listen for a response on the tempTopic
> Message request = session.createMessage();
> TemporaryTopic replyTopic = session.createTemporaryTopic();
> request.setJMSReplyTo(tempTopic);
> producer.send(request);
> Message reply = consumer.receive();
>
> // you could also use TopicRequestor to achieve the above.
>
> // Server
> Topic topic = context.lookup("mytopic");
> Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
> MessageConsumer consumer = session.createConsumer(topic);
>
> // listen for a request and send a response to the request's JMSReplyTo
> topic
> Message request = consumer.receive();
> Message response = session.createMessage();
> MessageProducer producer = session.createProducer(message.getJMSReplyTo());
> producer.send(response);
>
>
> OpenJMS does allow you to create non-persistent destinations on the fly
> using the createTopic() and createQueue().
> Note however that this is non-portable.
>
> -Tim
>

Ahh thanks Tim, this makes it more clear on TemporaryTopic usage.

-- 
"Nothing is impossible for the person that doesn't have to do it"
"The probability of anything happening is in inverse ratio to its desirability"
"If I were a roman statue, I'd be made alabastard"
--
George H
[email protected]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/