Announcement Announcement Module
No announcement yet.
Request - Response JMS message correlation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request - Response JMS message correlation

    Hi everyone...

    I have a question, obviously

    How does SpringWS handle JMS message correlation?
    Request JMS message goes from a client to a queue, it gets handled by the service, a response JMS message goes to another queue, and the client-side code correlates them how? I can't seem to find any logic in the JmsSenderConnection class which would indicate the nature of the correlation process...

    Thanks in advance!

  • #2
    Typically, a temporary queue is used for the response message. So any message arriving on that queue is the response.


    • #3
      OK, i got that part. What if have a permanent response queue? If it is not empty, and a client sends a request, will it pick up the first message it finds? That would be very undesired behavior....

      Thanks in advance!


      • #4
        Same problem

        We have the same problem. We have a permanent queue for receiving responses. See the following configuration.

        <bean id="client" class="">
          <constructor-arg ref="messageFactory" />
          <property name="messageSender">
            <bean class="">
              <property name="destinationResolver">
                <bean class="">
              <property name="receiveTimeout" value="15000" />
           <property name="marshaller">			
             <bean class="org.springframework.oxm.castor.CastorMarshaller" />
         <property name="defaultUri" value="jms:REQUEST_TO_BACKEND?replyToName=REPLY_FROM_BACKEND;deliveryMode=NON_PERSISTENT" />
        I prefer to use the correlationId in the JmsSenderConnection. It's easy to implement because we can query the properties of the request message.


        • #5
          Originally posted by jethrobakker View Post
          Currently, the JmsReceiverConnection sets the correlation id to the message id of the client request:

          However, if I look at at Spring Core's JmsInvokerServiceExporter, I see that it sets the CorrelationId to the client's correlation id:

          Basically, I am not sure which option is correct, so I am open for suggestions here...


          • #6

            The first code snip isn't correct, you shouldn't mix messageid and correlationid. MessageId is set by the JMS provider and it out of the user's control. CorrelationId is set by the user and is the expected place in the message to get data to correlate messages.

            As for temp queue vs permanent queue for the response. If the response message is part of modeling a sync request/reply interaction on top of JMS, then temp queues are the way. This ensures that resources (destinations) get cleaned up by the JMS provider. However, if the response is really a formal channel for ongoing communication between the two programs, a permanent queue makes sense and it is up to the response processing logic to pair it up with the initial request.

            Last edited by Mark Pollack; Jun 19th, 2008, 06:34 AM. Reason: minor edits to make it coherent :)


            • #7
              So basically, we need a way for the client to set the correlation id, because by default, it's empty.

              I guess this makes more pressing...


              • #8
                Two things:

                One, you can get a reference to the outgoing JMS request in the template, to set message properties, like so:

                        webServiceTemplate.sendSourceAndReceiveToResult(new StringSource(content), new WebServiceMessageCallback() {
                            public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
                                TransportContext transportContext = TransportContextHolder.getTransportContext();
                                JmsSenderConnection connection = (JmsSenderConnection) transportContext.getConnection();
                                String corrID = Long.toString(System.currentTimeMillis());
                                try {
                                catch (JMSException e) {
                                    throw new JmsTransportException(e);
                        }, result);
                Similar code will work on the server-side as well. Getting access to the response message is a different matter, because the response is created later.

                Two, the proposed SOAP over JMS spec says this:

                A correlated response message is one where the value of the JMSCorrelationID header field is the same as the value of the JMSMessageID of the request message.
                So it seems Spring-WS is doing the Right Thing, at least in regard to this spec. The only thing we don't do is create a message selector to listen for messages with a specific correlation id. Something like:

                JMSCorrelationID = 'ID:Mac-Pro.local-55591-1213880396995-2:1:1:1:1'
                I've created for this purpose, will be fixed in 1.5.3.


                • #9
                  The second thing would solve my problem. So, it would be great when it is fixed in the 1.5.3 release.