【问题标题】:How to send header message in JmsTemplate?如何在 JmsTemplate 中发送标头消息?
【发布时间】:2018-03-01 22:30:04
【问题描述】:

我正在尝试将消息头插入 amq。 JMSTemplate 中没有用于在 amq 中设置标头的特定方法。当我这样设置时,它将保存在 StringProperty 而不是标题中。保存到 header 如何传递数据

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

我需要将数据发送到标头中,客户端将为我的消息标头实现选择器。

【问题讨论】:

  • 这个问题有答案吗?
  • 我在路由上使用了查询,以便选择器端使用该查询来获取数据。- from("route?selector='yourSelector'")

标签: spring camera spring-jms jmstemplate amq


【解决方案1】:

您通过设置字符串属性来做到这一点。现在您的客户端应该能够根据消息选择器接收消息了。

例如在 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>

【讨论】:

  • 是的,但我的问题是..当我使用 apache Camel 并喜欢这个 exchange.getIn().setHeader("Country", "US");-- 它会在标题中设置但是当我使用上面的 - message.setStringProperty("Country","US");在 JMStemplate 中它将设置在 StringProperty 中。我需要来自 JMSTemplate 的消息头。
猜你喜欢
  • 2015-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多