Results 1 to 3 of 3

Thread: How does one set a JMSReplyTo on an SI Message?

  1. #1
    Join Date
    Mar 2007
    Posts
    16

    Default How does one set a JMSReplyTo on an SI Message?

    Hello,

    I would like to use SpringIntegration (SI) to send a StringMessage on an SI channel which then gets placed onto a JMS queue using the JMS channel adapter. I have this scenario set up using two channels, and endpoint, and a jms-target in my configuration. Everything is working fine, but here is the rub:

    When my message reaches the JMS queue, it is picked up by another system (that I cannot modify) which looks for a JMSReplyTo field in the JMSMessage header to determine which queue receives the transformed reply message.

    I have the following questions:

    1. Is it possible to set the JMSReplyTo field on my SI StringMessage object using an SI MessageHeader with fooHeader.setAttribute("JMSReplyTo", replyToDestination)?

    2. If that approach is possible, what is the best way to set a MessageHeader ? I see that the GenericMessage.setHeader() method has protected access. Must I subclass GenericMessage or StringMessage to be able to set a header?

    Thanks in advance for any advice on this matter!

    Thanks,

    Brad

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

    Default

    Brad,

    Currently, the easiest way to add the JMSReplyTo property would be to set a MessageConverter on the JmsTemplate. For example:
    Code:
    <si:jms-target jms-template="jmsTemplate" channel="outChannel"/>
    
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
       <property name="connectionFactory" ref="connectionFactory"/>
       <property name="defaultDestinationName" value="queue.out"/>
       <property name="messageConverter">
          <bean class="example.CustomConverter">
              <property name="replyTo" ref="replyDestination"/>
          </bean>
       </property>
    </bean>
    Then CustomConverter can extend Spring's SimpleMessageConverter, and do something like the following:
    Code:
    public void setReplyTo(Destination replyTo) {
       this.replyTo = replyTo;
    }
    
    public Message toMessage(Object o, Session s) {
       Message message = super.toMessage(o, s);
       message.setJMSReplyTo(this.replyTo);
       return message;
    }
    Moving forward, the Spring Integration JmsTargetAdapter should probably be able to recognize these common JMS headers. The keys can be provided as static fields in the adapter itself (e.g. JmsTargetAdapter.JMS_REPLY_TO). Then, what you are trying to do would be much easier. I will add this right now as an M2 issue in Jira.

    To answer your question about the header, you can add attributes like this:
    Code:
    message.getHeader().setAttribute("key", value);
    Hope that helps,
    Mark

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

    Default

    If you want to check on the progress, here is a link to the Jira issue for this: http://jira.springframework.org/browse/INT-97

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