Announcement Announcement Module
Collapse
No announcement yet.
How to get the response from REPLY QUEUE with correlation ID received from request? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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Ԣ‡–nLaԢ‡–nL–™ƒ…n La–™ƒ…nLԢ‡…†–nLaԢ‡…†–n L–‡–•n@@@@@@@@La–‡–•nLn@@@@@@@@@@@@@@@@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, 12:41 PM.

  • #2
    What is the receiving system doing?

    This correlation pattern requires the receiving system to copy the inbound JMSMessageID to the JMSCorrelationID.

    Comment


    • #3
      Also, you might want to consider using Spring Integration - the <jms:outbound-gateway/> will handle all this for you.

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment


          • #6
            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

            Comment


            • #7
              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.

              Comment


              • #8
                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

                Comment


                • #9
                  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, 05:36 PM.

                  Comment


                  • #10
                    Hi,

                    Thanks. I will try with this approach.

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


                    Thanks

                    Comment

                    Working...
                    X