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.

sudar
  • 1,446
  • 2
  • 14
  • 26
  • Did get any answer to this? – Yati Sawhney May 30 '18 at 09:15
  • I used the query on my route so that selector side uses that query to grab data.- from("route?selector='yourSelector'") – sudar May 30 '18 at 13:14
  • @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. – M S Kulkarni Oct 10 '22 at 21:16

1 Answers1

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>
Monzurul Shimul
  • 8,132
  • 2
  • 28
  • 42
  • 1
    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. – sudar Sep 22 '17 at 19:52
  • 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) – BitfulByte Jan 25 '22 at 17:15