How to send header message in JmsTemplate?
Asked Answered
P

1

8

I am trying to insert message header into amq. There is no specific method in JMSTemplate for setting header in amq. when I set like this it will save in StringProperty instead of header. For saving into header how to pass data

 amqTemplate.convertAndSend(goMQ, message,new MessagePostProcessor() {
      @Override
        public Message postProcessMessage(Message message) throws JMSException {
            message.setStringProperty("test1","testdata");
            message.setStringProperty("country","US");
          //setObjectProperty -- also set the string property 
            return message;
        }
    });

I need to send the data into header and client will implement selector for my message header.

Pedlar answered 20/9, 2017 at 18:21 Comment(3)
Did get any answer to this?Essentialism
I used the query on my route so that selector side uses that query to grab data.- from("route?selector='yourSelector'")Pedlar
@sudar, did you find an answer for this question? I ran into same issue, but could not find a way to include it as a header. Please let me know if you have found a way to include it in header.Menstrual
L
0

You are doing it right by setting string property. Now your client should be able to receive message based on message selector.

For example in jms, client will get message only for country "US" with following settings:

           <activation-config>
                <activation-config-property>
                    <activation-config-property-name>destinationType</activation-config-property-name>
                    <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                    <activation-config-property-name>destinationJNDIName</activation-config-property-name>
                    <activation-config-property-value>jms/queueName</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                    <activation-config-property-name>messageSelector</activation-config-property-name>
                    <activation-config-property-value>country='US'</activation-config-property-value>
                </activation-config-property>
            </activation-config>
Loisloise answered 21/9, 2017 at 15:23 Comment(2)
Yes that is but my question is .. when I used apache Camel and do like this exchange.getIn().setHeader("Country", "US");-- It will set in header but when I use the above one -- message.setStringProperty("Country","US"); in JMStemplate It will set in StringProperty . I need message header from JMSTemplate.Pedlar
I was looking at the same "issue" but actually found that it doesn't matter for Camel. The implementation was working just as fine. (I'm using the plain vanilla JMS setup for E2E automated testing purposes)Birdsong

© 2022 - 2024 — McMap. All rights reserved.