如何在JmsTemplate中发送头部消息?

8

我正在尝试向amq中插入消息头。JMSTemplate中没有特定的方法可以在amq中设置头文件。当我像这样设置时,它将保存在StringProperty中而不是头文件中。要保存到头文件中,如何传递数据?

 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;
        }
    });

我需要将数据发送到头部,客户端将实现选择器以获取我的消息头。


这个问题有未获得任何答案吗? - Yati Sawhney
我在我的路由中使用了查询,以便选择器端使用该查询来获取数据。- from("route?selector='yourSelector'") - sudar
@sudar,你找到这个问题的答案了吗?我也遇到了同样的问题,但是找不到在头部包含它的方法。如果你已经找到了一种方法,请告诉我如何在头部包含它。 - M S Kulkarni
1个回答

0

您设置字符串属性是正确的。现在,您的客户端应该能够根据消息选择器接收消息。

例如,在JMS中,客户端将仅获取以下设置的“美国”国家的消息:

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

1
是的,但我的问题是...当我使用Apache Camel并像这样执行时 exchange.getIn().setHeader("Country", "US");-- 它会设置在头部,但当我使用上面的 -- message.setStringProperty("Country","US"); 在JMStemplate中它将设置为StringProperty。我需要来自JMSTemplate的消息头。 - sudar
我曾经遇到过同样的“问题”,但实际上发现这对 Camel 来说并不重要。该实现运作正常。(我正在使用纯净的香草 JMS 设置进行 E2E 自动化测试。) - BitfulByte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接