Announcement Announcement Module
No announcement yet.
How to access a JMSCorrelationID in Spring Integration? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?



  • #2
    It seems that other that reading the source you're only information is this:

    from the source of DefaultJmsMessagePostProcessor:
    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
      I have created a new issue for this:

      It is essentially the same idea as 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.



      • #4
        I have created a new issue for this:
        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

          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:
          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:
          message.getHeader().setAttribute(JmsAttributeKeys.CORRELATION_ID, jmsCorrelationId);
          Hope that helps.