gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:03:23 26 4
gpt4 key购买 nike

我正在尝试将消息头插入 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;
}
});

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

最佳答案

通过设置字符串属性,您可以正确地做到这一点。现在您的客户端应该能够接收基于消息选择器的消息。

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

关于spring - 如何在 JmsTemplate 中发送标题消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com