如何在spring集成中为每个出站jms消息设置优先级?

如何在spring集成中为每个出站jms消息设置优先级?,jms,spring-integration,ibm-mq,Jms,Spring Integration,Ibm Mq,嘿,我正在使用spring集成的jms:outbound channel adapter,在将消息推送到消息传递系统之前,需要设置消息的优先级 现在在普通JMS中,我有两种方法 在消息生产者上设置优先级: this.producer.setPriority(i); 或在发送方法本身上: channel.send(message, DeliveryMode.PERSISTENT, 5, 1000); 这两个选项都不再适用于我,因为通道适配器将我从这些细节中抽象出来 在消息本身上设置优先级只在s

嘿,我正在使用spring集成的
jms:outbound channel adapter
,在将消息推送到消息传递系统之前,需要设置消息的优先级

现在在普通JMS中,我有两种方法

消息生产者
上设置优先级:

this.producer.setPriority(i);
或在发送方法本身上:

channel.send(message, DeliveryMode.PERSISTENT, 5, 1000);
这两个选项都不再适用于我,因为通道适配器将我从这些细节中抽象出来

在消息本身上设置优先级只在spring integration的内存
通道中起作用,并且在我将其放入实际队列时立即失效。事实证明,设置消息的优先级根本不是一个选项:

通道适配器上有一个属性,我可以在其中设置优先级,但这是静态的

    <jms:outbound-channel-adapter id="101Out" 
                              channel="101MessageChannel"
                              connection-factory="101Factory"
                              destination="QUEUE_NAME"
                              priority="1" />
一旦确定了优先级,我就将消息路由到相应的出站适配器。但是如果优先级增加,我就有麻烦了。即使没有,但我认为,拥有两个出站适配器而不是一个,因为我无法动态分配优先级,这有点笨拙

感谢您的帮助:-)


哦,我正在使用WebSphereMQ作为我的消息代理。我不知道这是否与message broker有关。

只需在消息中设置优先级头

<int:header-enricher ...>
    <int:priority value="2" />
</int:heaer-enricher>

适配器配置中的优先级是默认值,在没有优先级标头时使用(您可以使用属性占位符从属性文件设置优先级)

或者,使用一个表达式

<int:header-enricher ...>
    <int:priority expression="payload.foo == 'bar' ? 1 : 2" />
</int:heaer-enricher>

<int:header-enricher ...>
    <int:priority expression="payload.priority" />
</int:heaer-enricher>

<int:header-enricher ...>
    <int:priority expression="@someBean.calculatePriority(payload)" />
</int:heaer-enricher>


我仍然在进行静态查找,对吗?我现在有两个标头充实器和一个通道适配器,而不是两个通道适配器。我需要一种从负载本身查找数据并将其分配给优先级的方法。如果没有这些,我只会为添加的每个新优先级编写额外的enricher。在头enricher中使用一个表达式:
等等。哦,太棒了。这完全简化了事情。谢谢!虽然这个答案是正确的,但从SpringIntegration4.1.0.RC1开始(至少到5.2.3.0版本为止,取决于底层JMS提供程序),这一点就被打破了,请参阅
<int:header-enricher ...>
    <int:priority expression="payload.foo == 'bar' ? 1 : 2" />
</int:heaer-enricher>

<int:header-enricher ...>
    <int:priority expression="payload.priority" />
</int:heaer-enricher>

<int:header-enricher ...>
    <int:priority expression="@someBean.calculatePriority(payload)" />
</int:heaer-enricher>