Results 1 to 10 of 10

Thread: How to get the response from REPLY QUEUE with correlation ID received from request?

  1. #1
    Join Date
    Apr 2010
    Posts
    7

    Default How to get the response from REPLY QUEUE with correlation ID received from request?

    Hi,

    I am using the below code to send message
    Code:
    public String sendMessage(final String text) {
    		System.out.println("requestQueue: "+requestQueue);
    		MyMessageCreator messageCreator =
    	        new MyMessageCreator(text);
    		
    		String correlationId = null;
    		try
    		{
    			jmsTemplate.send("REQ.INQ.01", messageCreator);
    			correlationId = messageCreator.message.getJMSMessageID();
    		}
    		catch(Exception e)
    		{
    			System.out.println("Exception has Occured");
    		}
    		System.out.println("correlationId"+correlationId);
    		
    		return correlationId;
    	}
    Below code to receive message
    Code:
    public String readMessage() throws JMSException {
    		String message = null;
                                String resSelectorId = "JMSCorrelationID = '"+correlationId+"'";
    		System.out.println("responseQueue: "+responseQueue);
    		//Message msg = jmsTemplate.receive("RPL.INQ.01");
    		Message msg = jmsTemplate.receiveSelected("RPL.INQ.01",resSelectorId);
    
    }
    It fails when I use jmsTemplate.receiveSelected("RPL.INQ.01",resSelect orId); ....There is no response received.


    Application returns ByteMessages with all Junk characters when I use
    Message msg = jmsTemplate.receive("RPL.INQ.01");

    Junk is too length..I am pasting the message which chracters it starts with..

    LÔ¢‡nLÔ¢‡È…?„…™nLÔ¢‡Õ–nðððððððñLaÔ¢‡Õ–nLâ–¤™ƒ…nòðñ Laâ–¤™ƒ…nLÔ¢‡Ù…†Õ–nÉåñòðñóðñóñðððððððñòLaÔ¢‡Ù…†Õ–n LÓ–‡–•ÉÄn@@@@@@@@LaÓ–‡–•ÉÄnL×ÁÕn@@@@@@@@@@@@@@@@La ×ÁÕnLã§•Ã

    I wanted to make it synchrounous and get the response..Please advice to resolve the issue.


    I could put the message and get the message ID for request from MQ as well...

    Also I could see correct response received on the MQ explorer but I get junk characters in program response.


    Thanks
    Last edited by Gary Russell; Feb 7th, 2013 at 11:41 AM.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,142

    Default

    What is the receiving system doing?

    This correlation pattern requires the receiving system to copy the inbound JMSMessageID to the JMSCorrelationID.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,142

    Default

    Also, you might want to consider using Spring Integration - the <jms:outbound-gateway/> will handle all this for you.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #4
    Join Date
    Apr 2010
    Posts
    7

    Default

    Hi,

    Thanks for the response.

    I have a logic to copy the ID received from request queue and use it while getting the message from response queue.

    String resSelectorId = "JMSCorrelationID = '"+correlationId+"'";
    Message msg = jmsTemplate.receiveSelected("RPL.INQ.01",resSelect orId);

    But this one is not working only getting null Message Object. But the message is there in the resposne queue with the correlation id I have passed.

    Receiving system is expecting the xml response to parse and use it.

    Thanks

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,142

    Default

    Right, I see what you are doing on the client, but your selector requires the message id in the correlation id header - this means the receiving system MUST copy the inbound message id to the outbound correlation id. If it doesn't do that, your selector won't work.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6
    Join Date
    Apr 2010
    Posts
    7

    Default

    Hi,

    Thanks..I am bit confused now..sorry..

    Below line retrives the message id after sending the request and assigns it to correlationId .
    correlationId =messageCreator.message.getJMSMessageID()

    ID received from request is used to construct resSelectorId and passed in receiveSelected function
    String resSelectorId = "JMSCorrelationID = '"+correlationId+"'";
    Message msg = jmsTemplate.receiveSelected("RPL.INQ.01",resSelect orId);

    Actually this my understandin to copy the inbound message id to the outbound correlation id.

    Please help me to understand if i have to add some other steps.

    Thanks

  7. #7
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,142

    Default

    Right, but that's on the CLIENT side - if the RECEIVING system doesn't place the INBOUND message ID in the REPLY correlationId, your selector won't work.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  8. #8
    Join Date
    Apr 2010
    Posts
    7

    Default

    Hi,

    I have verified the response message.
    Response message correlationid matched with Request message message id.
    It works when i use java mq classes. I wanted to use spring...

    Thanks

  9. #9
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,142

    Default

    Well, you can't capture the JMSMessageID from the raw message before you send it (I presume you are trying to capture it in your MessageCreator).

    There might be better ways to do it, but this works fine...

    Code:
    		String id = template.execute(new SessionCallback<String>() {
    			@Override
    			public String doInJms(Session session) throws JMSException {
    				TextMessage message = session.createTextMessage();
    				message.setText("foo");
    				Destination replyQ = session.createQueue("reply.demo");
    				message.setJMSReplyTo(replyQ);
    				Queue queue = session.createQueue("queue.demo");
    				MessageProducer producer = session.createProducer(queue);
    				producer.send(message); // populates the message id
    				return message.getJMSMessageID();
    			}
    		});
    
    		System.out.println("<" + id + ">");
    
    		String selector = "JMSCorrelationID='" + id + "'";
    
    		TextMessage reply = (TextMessage) template.receiveSelected("reply.demo", selector);
    		System.out.println(reply.getText());
    But, like I said, use a Spring Integration outbound gateway and all the low-level stuff is taken care of for you.
    Last edited by Gary Russell; Feb 8th, 2013 at 04:36 PM.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  10. #10
    Join Date
    Apr 2010
    Posts
    7

    Default

    Hi,

    Thanks. I will try with this approach.

    I will explore on the Spring Integration outbound gateway as well.


    Thanks

Posting Permissions

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