Results 1 to 10 of 10

Thread: getting synchronous reply from SPRING JMS

  1. #1
    Join Date
    Sep 2007
    Posts
    10

    Default getting synchronous reply from SPRING JMS

    Hi,

    i have used jmsTemplate.send(queueName,new StringMessage(selectorText,input));
    i have overriden like

    public Message createMessage(Session session) throws JMSException
    {

    Message message = session.createTextMessage(strInput);
    message.setStringProperty("service", strMessage);
    return message;
    }

    But i want to receive reply also synchronously.
    But receive methods does not have MessageCreator as argument.

  2. #2
    Join Date
    Sep 2007
    Posts
    10

    Default

    I have written the class

    import javax.jms.JMSException;
    import javax.jms.MessageProducer;
    import javax.jms.Session;
    import javax.jms.TemporaryQueue;
    import javax.jms.TextMessage;

    import org.springframework.jms.core.ProducerCallback;

    public class IPLJmsQueueRequestor implements ProducerCallback{

    private String strMessage = null;
    private String strInput = null;
    private String queueName = null;

    public IPLJmsQueueRequestor(String strMessageSelector,String strInput,String queueName)
    {
    System.out.println(" inside constructor of IPLJmsQueueRequestor");
    this.strMessage = strMessageSelector;
    this.strInput = strInput;
    this.queueName = queueName;
    }

    public Object doInJms(Session session, MessageProducer producer) throws JMSException {
    System.out.println("inside IPLJmsQueueRequestor");
    TemporaryQueue queue = session.createTemporaryQueue();
    TextMessage message = session.createTextMessage();
    message.setText(strInput);
    message.setStringProperty("service", strMessage);
    message.setJMSReplyTo(queue);

    producer.send(session.createQueue(queueName), message);
    return session.createConsumer(queue).receive();
    }


    }

    But doInJms is not getting called.

    i am calling like

    public Message executeSynchronously(String queueName,String input,String selectorText) {
    Message returnMess = null;
    try
    {
    System.out.println("inside executeSynchronously");
    returnMess = (Message)jmsTemplate.execute(new IPLJmsQueueRequestor(selectorText,input,queueName) );
    }
    catch(Exception e){System.out.println(e);}
    return returnMess;

    }

    Any suggestion ?

  3. #3
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hello,

    please don't post at two threads for the same problem.

    You can use the jmstemplate.receiveSelected(String); method, where the argument is the messageselector condition.

    rgds
    agim

  4. #4
    Join Date
    Sep 2007
    Posts
    10

    Default

    Hi,

    Sorry for two posts.
    You want to say that after sending jmsTemplate.send(queueName,new StringMessage(selectorText,input));
    i should do receiveSelected to get the response back.

    Please confirm

  5. #5
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    yes,
    there are also lots of documentation inside the javadocs avaiable.

    rgds

  6. #6
    Join Date
    Sep 2007
    Posts
    10

    Default

    Hi,

    I guess i am unable to tell you my requirement. I only want the response to come back.

    If i do like

    jmsTemplate.send(queueName,new StringMessage(selectorText,input));
    Message mess = jmsTemplate.receive(queueName);

    then TIBCO which is consuming this message and after processing when trying to send the response back using JMS-REPLY-TO component then getting following error

    Caused by: java.lang.Exception: no message to reply to
    at com.tibco.plugin.share.jms.impl.JMSReplySender.sen d(JMSReplySender.java:139)
    ... 8 more

  7. #7
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hello,

    now you have hit the point. I was a little bit confused with your last problem (selectors). In your case you have to use a SessionCallback or a Producercallback. The reason is that temporary queues are only open within the session that has created it. So you have to use the same session for sending and receiving the message. (Otherwise the temporary queue is deleted while closing the session).

    You can send and receive the message like you have done in your code.

    Code:
    public Object doInJms(Session session, MessageProducer producer) throws JMSException {
    System.out.println("inside IPLJmsQueueRequestor");
    TemporaryQueue queue = session.createTemporaryQueue();
    TextMessage message = session.createTextMessage();
    message.setText(strInput);
    message.setStringProperty("service", strMessage);
    message.setJMSReplyTo(queue);
    
    producer.send(session.createQueue(queueName), message);
    return session.createConsumer(queue).receive();
    }
    In this case you also don't need a selector to receive the message, because the temporary queue is dedicated to the session. So you should receive only and exactly one reply message inside the reply queue.

    In your code you should think about of using a timeout while waiting for the external system. Because otherwise you will wait until the shutdown of the message system.

    Hope this clarifies a little bit. If you have further questions feel free to ask.

    rgds
    agim

  8. #8
    Join Date
    Sep 2007
    Posts
    10

    Default

    Hi,

    Thanks but as i told you earlier somehow doInJms is not getting called.
    I need message selector for sending the message as the TIBCO JMS is filtering out with that selector thats why i have set setStringProperty. While receiving i guess i dont need any selector.

    But the bottom line is when i am using ProducerCallback i am unable to call the service which is consuming message as JMS Consumer in TIBCO.

    Any suggestion.

    Thanks and Regards,
    Kundan

  9. #9
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hello,

    Thanks but as i told you earlier somehow doInJms is not getting called.
    I have tested you code and the roducer callback is called like expected. Could you please switch on the debug log and have a look what happens.

    You should see output like this line

    Code:
    2007-09-14 17:18:14,343 DEBUG [org.springframework.jms.core.JmsTemplate] - Executing callback on JMS Session [ActiveMQSession {id=ID:nb-agim2-3457-1189783094078-1:0:1,started=false}]
    inside IPLJmsQueueRequestor
    rgds
    agim

  10. #10
    Join Date
    Jul 2008
    Location
    Toronto
    Posts
    1

    Default Simple Spring JMS Example

    There are a couple of very straight-forward "hello world" type examples of setting using JMS in Spring 2.5 available at blog.justtechnologies.ca

    The first, blog.justtechnologies.ca/2008/07/implementing-jms-message-listener-in.html, describes how to set up a message listener.
    The second, blog.justtechnologies.ca/2008/07/using-replyto-destinations-with-spring.html, builds on the first to allow sending a reply message. Sending to an arbitrary queue would be the same, but with a different destination.

    I hope you find these helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •