简体   繁体   English

activemq优先级

[英]Priority with activemq

We're currentyly developping an application using JMS and activemq (5.5.1). 我们目前正在使用JMS和activemq(5.5.1)开发应用程序。 We would like to define a higher priority for some messages, which would make them consumed first. 我们希望为某些消息定义更高的优先级,这将使它们首先被消耗。 After setting the producer and the consumer (through spring (3.1) JMSTemplate), the priority does not fully work. 设置生产者和消费者(通过spring(3.1)JMSTemplate)后,优先级不能完全发挥作用。 Indeed, when we "turn off" the consumer, and send some messages, the priority is respected, but when we add messages while the consumer is on, the messages are received in the same order they were sent. 实际上,当我们“关闭”消费者并发送一些消息时,优先级得到尊重,但是当我们在消费者开启时添加消息时,消息的接收顺序与发送消息的顺序相同。

The configuration is quite simple: 配置很简单:

Priority was activated in the activemq config file: 在activemq配置文件中激活优先级:

<policyEntries>
  <policyEntry queue=">" prioritizedMessages="true"/>
  ...
</policyEntries>

And QoS was enabled in the producer template configuration: 并且在生产者模板配置中启用了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>

To send a message with a high priority, we just change the template priority property on the producer side: 要发送具有高优先级的消息,我们只需更改生产者端的模板优先级属性:

template.setPriority(9);

Any idea? 任何的想法? Is this the normal behaviour, or is there some configuration we would have forgotten? 这是正常的行为,还是有一些我们会忘记的配置?

If my opinion you are not missing anything, I had a similar issue a couple of weeks ago (but with TTL and QPid). 如果我的意见你没有遗漏任何东西,几周前我有一个类似的问题(但使用TTL和QPid)。

First the JMS is not Strict about this : 首先,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.

Second, ActiveMQ does not YET implement priority queues, they say it will somewhere in 6.x version. 其次,ActiveMQ没有实现优先级队列,他们说它会在6.x版本的某个地方。

So, what you see is actually normal. 所以,你看到的实际上是正常的。

As a work-around you can use the Resequencer pattern if it fits your case. 作为解决方法,如果适合您的情况,您可以使用Resequencer模式。

http://camel.apache.org/resequencer.html http://camel.apache.org/resequencer.html

Here is another discussion on this subject: 这是关于这个主题的另一个讨论:

http://activemq.2283324.n4.nabble.com/Priority-message-td2352179.html http://activemq.2283324.n4.nabble.com/Priority-message-td2352179.html

I know it is late but this answers may help somebody. 我知道它已经晚了,但这个答案可能对某些人有所帮助。

If you want your consumer to consume message based on priority (Priority Queue) then you can use client side message priority. 如果您希望消费者根据优先级(优先级队列)使用消息,则可以使用客户端消息优先级。 This means, when messages are being sent to your consumer (even before your consumer is receiving them, using prefetch), they will be cached on the consumer side and prioritized by default. 这意味着,当消息发送给您的消费者时(甚至在您的消费者使用预取之前接收消息之前),它们将被缓存在消费者端并默认优先级。 This is regardless of whether you're using priority support on the broker side. 无论您是否在代理方使用优先支持,这都是一样的。 This could impact the ordering you see on the consumer so just keep this in mind. 这可能会影响您在消费者身上看到的顺序,所以请记住这一点。

To enable it, set the following configuration option on your broker URL, eg, 要启用它,请在代理URL上设置以下配置选项,例如,

tcp://0.0.0.0:61616?jms.messagePrioritySupported=true

To disable it, tcp://0.0.0.0:61616?jms.messagePrioritySupported=false 要禁用它, tcp://0.0.0.0:61616?jms.messagePrioritySupported=false

So you do not require to use Camel (if you want to avoid complication) 所以你不需要使用Camel(如果你想避免并发症)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM