如何在 JmsTemplate 中发送标题消息?

sud*_*dar 7 spring camera jmstemplate spring-jms amq

我正在尝试将消息头插入 amq。JMSTemplate 中没有特定方法用于在 amq 中设置 header。当我这样设置时,它将保存在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;
        }
    });
Run Code Online (Sandbox Code Playgroud)

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

Mon*_*mul 0

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

例如,在 jms 中,客户端将仅收到具有以下设置的国家/地区“US”的消息:

           <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>
Run Code Online (Sandbox Code Playgroud)