• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMS : USING JMS ReplyTo Queue

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 -
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just off the top of my head:

 
Anand Sidharth
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic