当前,我们正在使用JMS和activemq(5.5.1)开发应用程序。
我们想为某些消息定义更高的优先级,这将使它们首先被使用。
在设置了生产者和使用者之后(通过Spring(3.1)JMSTemplate),优先级不能完全发挥作用。
确实,当我们“关闭”使用者并发送一些消息时,优先级得到了尊重,但是当我们在使用者打开时添加消息时,消息的接收顺序与发送时相同。
配置非常简单:
在activemq配置文件中激活了优先级:
<policyEntries>
<policyEntry queue=">" prioritizedMessages="true"/>
...
</policyEntries>
并且在生产者模板配置中启用了QoS:
<bean id="jmsOCRTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="destination_ocr" />
<property name="explicitQosEnabled" value="true" />
</bean>
要发送高优先级的消息,我们只需在生产者端更改模板优先级属性:
template.setPriority(9);
任何想法?这是正常的行为,还是我们会忘记一些配置?
最佳答案
如果我认为您没有丢失任何东西,则几周前我遇到了类似的问题(但使用TTL和QPid)。
首先,JMS对此并不严格:
JMS does not require that a provider strictly implement priority ordering of messages; however, it should do its best to deliver expedited messages ahead of normal messages.
其次,ActiveMQ尚未实现优先级队列,他们说它将在6.x版本中实现。
因此,您看到的实际上是正常的。
作为解决方法,如果适合您的情况,可以使用Resequencer模式。
http://camel.apache.org/resequencer.html
这是关于此主题的另一个讨论:
http://activemq.2283324.n4.nabble.com/Priority-message-td2352179.html