Announcement Announcement Module
Collapse
No announcement yet.
Request - Response JMS message correlation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Comment


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

      Comment


      • #4
        Same problem

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

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

        Comment


        • #5
          Originally posted by jethrobakker View Post
          I prefer to use the correlationId in the JmsSenderConnection. It's easy to implement because we can query the properties of the request message.
          Currently, the JmsReceiverConnection sets the correlation id to the message id of the client request:

          Code:
                      responseMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());
          However, if I look at at Spring Core's JmsInvokerServiceExporter, I see that it sets the CorrelationId to the client's correlation id:

          Code:
          response.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
          Basically, I am not sure which option is correct, so I am open for suggestions here...

          Comment


          • #6
            Hi,

            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.

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

            Comment


            • #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 http://jira.springframework.org/browse/SWS-375 more pressing...

              Comment


              • #8
                Two things:

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

                Code:
                        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 {
                                    connection.getRequestMessage().setJMSCorrelationID(corrID);
                                }
                                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 http://jira.springframework.org/browse/SWS-383 for this purpose, will be fixed in 1.5.3.

                Comment


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

                  regards,

                  Jethro

                  Comment

                  Working...
                  X