Results 1 to 5 of 5

Thread: How to access a JMSCorrelationID in Spring Integration?

  1. #1
    Join Date
    Mar 2007
    Posts
    16

    Default How to access a JMSCorrelationID in Spring Integration?

    Hello, I have a quick question: does a Spring Integration (SI) MessageHeader.getCorrelationId() map to a JMS Message.getCorrelationID() ?

    In other words, I have an SI Message object "siMessage". I need to access the JMSCorrelationID that should have been set by another system at the JMS API level. Can I get this value by invoking siMessage.getHeader().getCorrelationId() ? If not, how would I access the JMSCorrelationID header value?

    Thanks,

    Brad

  2. #2
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    It seems that other that reading the source you're only information is this:
    http://jira.springframework.org/browse/INT-97.

    from the source of DefaultJmsMessagePostProcessor:
    Code:
    public void postProcessJmsMessage(Message jmsMessage, MessageHeader header) throws JMSException {
    		Object jmsCorrelationId = header.getAttribute(JmsTargetAdapter.JMS_CORRELATION_ID);
    		if (jmsCorrelationId != null && (jmsCorrelationId instanceof String)) {
    			jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
    		}
    		Object jmsReplyTo = header.getAttribute(JmsTargetAdapter.JMS_REPLY_TO);
    		if (jmsReplyTo != null && (jmsReplyTo instanceof Destination)) {
    			jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
    		}
    		Object jmsType = header.getAttribute(JmsTargetAdapter.JMS_TYPE);
    		if (jmsType != null && (jmsType instanceof String)) {
    			jmsMessage.setJMSType((String) jmsType);
    		}
    	}
    It seems there is no correlation. As I read it you should use the Jms specific attributes instead of the default header stuff. Maybe Mark can explain the details more clearly

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    I have created a new issue for this: http://jira.springframework.org/browse/INT-150

    It is essentially the same idea as http://jira.springframework.org/browse/INT-49 but applied to the source adapter rather than just the target adapter (as currently). Please feel free to comment on the new issue if you have anything to add or any disagreements with the proposed solution.

    Thanks,
    Mark

  4. #4
    Join Date
    Mar 2007
    Posts
    16

    Default

    I have created a new issue for this: http://jira.springframework.org/browse/INT-150
    Hey Mark,

    I see that the above change has been made. We have just taken this morning's svn HEAD from spring-integration.

    Should I be able to leverage this latest change now, or do I need to wait for the 1.0.0.m3 release ?

    If the change is available, how do I use your latest change to access JMS headers such as JMSCorrelationID when given an incoming Spring Integration Message object? We are currently trying to invoke

    siMessage.getHeader().getCorrelationId() but are still getting null, but we are expecting a value there.

    We know the header value is present on the incoming JMS message, because when we use <jms:listener / > instead of <si:jms-source /> we are able to see the header value in our message handler by invoking jmsMessage.getJMSCorrelationId()

    I appreciate all your efforts and input!

    - Brad

  5. #5
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    Brad,

    This is available in the latest snapshot (e.g. nightly-77), and I'd be very interested in your feedback once you try the following...

    The JMSCorrelationId value is stored separately from the Spring Integration MessageHeader's correlationId. The rationale is that the former is related to an external system while the latter is used *within* Spring Integration messaging. To access the JMSCorrelationId after receiving a Message from a JMS source adapter, try this:
    Code:
    jmsCorrelationId = message.getHeader().getAttribute(JmsAttributeKeys.CORRELATION_ID);
    The value should be mapped automatically for incoming JMS Messages and also mapped automatically for outbound JMS Messages. That means that you can also set the value prior to sending to a JMS target adapter like so:
    Code:
    message.getHeader().setAttribute(JmsAttributeKeys.CORRELATION_ID, jmsCorrelationId);
    Hope that helps.
    -Mark

Posting Permissions

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