aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JMS : USING JMS ReplyTo Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS : USING JMS ReplyTo Queue" Watch "JMS : USING JMS ReplyTo Queue" New topic
Author

JMS : USING JMS ReplyTo Queue

Anand Sidharth
Ranch Hand

Joined: Dec 17, 2003
Posts: 44
I am setting the replyTo queue in the message i send to a queue in the following way:

QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("TESTQMQCF");
QueueConnection connection = qcf.createQueueConnection();
Queue queue = (Queue)ctx.lookup("TESTQMQ");//remote queue
Queue replyqueue = (Queue)ctx.lookup("TESTQMQREPLY");//local queue
QueueSession session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
TextMessage outMessage = session.createTextMessage();
outMessage.setText(line);
outMessage.setJMSCorrelationID("ANAND");
outMessage.setJMSReplyTo(replyqueue);
sender.send(outMessage);

In the receiving end, a java program receives the message and gets the
JMSreplyTo queue.

QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("TESTQM100QCF");
QueueConnection connection = qcf.createQueueConnection();
Queue queue = (Queue)ctx.lookup("TESTQM100Q");//Local queue
QueueSession session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(queue);
connection.start();
outMessage = (TextMessage)receiver.receive(10000);
line = outMessage.getText();
Queue replyTo = (Queue) outMessage.getJMSDestination();

I want to post a message to this replyTo queue from the receiver side program. How can i put a message to this replyto queue?

Please suggest me a way -
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
Just off the top of my head:

Anand Sidharth
Ranch Hand

Joined: Dec 17, 2003
Posts: 44
Thanks Brian
But the problem is that the sender and receiver are different queue managers in different machines ....
In the code you sent,
the session object used is created using the connection formed from the QCF information of the receiver side ...
But the replyToQueue is present in the sender queuemanager.
How is it possible to send a message to the replyToQ using the receiver connection session? Or am i missing out something here
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
You're right, I didn't notice the difference in connection factories.

Have you tried doing a lookup on the other server to obtain the QueueConnectionFactory? You should be able to do that and I would think it would still work.

If the receiver doesn't know what server to connect back to, then perhaps you could add headers to the message containing that information so that you could create the proper InitialContext and lookup the correct QueueConnectionFactory.
Anand Sidharth
Ranch Hand

Joined: Dec 17, 2003
Posts: 44
Thanks Brian...
Since there could be hundreds of senders (there is only one receiver) there is no way to lookup to the particular sender server.

I think the second option you gave on sending the context info along with the message is a good solution. I would let you know after the implementation.

Actually i was thinking that since the name is 'replyTo' Queue, the JMS provider should take care of finding where the replyTo Queue is located and sending back the reply message i.e., the message object should have provision to form the qcf for the replyTo Queue.
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
The thing is, a Queue is not tied to a specific QueueConnectionFactory so there isn't any way for someone to look at a Queue and determine what QCF to use to write to it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMS : USING JMS ReplyTo Queue