【发布时间】:2016-01-17 15:13:18
【问题描述】:
嘿,所以我正在使用 spring 集成的 jms:outbound-channel-adapter 并且需要在将消息推送到消息传递系统之前设置消息的优先级。
现在在普通的 JMS 中,我有两种方法。
在MessageProducer 上设置优先级:
this.producer.setPriority(i);
或者在发送方法本身:
channel.send(message, DeliveryMode.PERSISTENT, 5, 1000);
这些选项对我都不再可用,因为通道适配器将我从这些细节中抽象出来。
设置消息本身的优先级仅适用于 spring 集成的内存中channels,并且在我将其放入实际队列时立即失效。结果证明设置消息的优先级根本不是一个选项:JMS message priority not working on Message
通道适配器上有一个属性,我可以在其中设置优先级,但这是静态的。
<jms:outbound-channel-adapter id="101Out"
channel="101MessageChannel"
connection-factory="101Factory"
destination="QUEUE_NAME"
priority="1" />
我可以从属性文件中读取的最大值。 (或者我认为。我不确定)。我可以使用destination-expression 属性来检查传入的消息并将其动态路由到不同的目的地,但是没有priority-expression 对应部分可以让我对优先级执行相同的操作。
我有一些解决方法,但不是很好:
<jms:outbound-channel-adapter id="101HighPriorityOut"
channel="101HighPriorityChannel"
connection-factory="101Factory"
destination-expression="headers.QUEUE_NAME"
priority="1"
explicit-qos-enabled="true" />
<jms:outbound-channel-adapter id="101LowPriorityOut"
channel="101LowPriorityChannel"
connection-factory="101Factory"
destination-expression="headers.QUEUE_NAME"
priority="0"
explicit-qos-enabled="true" />
一旦确定需要什么优先级,我只需将消息路由到适当的出站适配器。但是,如果优先级的数量增加,我就会遇到麻烦。即使没有,拥有两个出站适配器而不是一个,因为我无法动态分配优先级,我认为这有点笨拙。
感谢帮助:-)
哦,我正在使用 Websphere MQ 作为我的消息代理。我不知道这是否与消息代理有关。
【问题讨论】:
标签: jms spring-integration ibm-mq