6
votes

We're currentyly developping an application using JMS and 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. 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:

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

And QoS was enabled in the producer template configuration:

<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?

2
You might want to give the latest ActiveMQ 5.6-SNAPSHOT a go as it has several fixes in the area of priority that could improve your situation.Tim Bish

2 Answers

7
votes

If my opinion you are not missing anything, I had a similar issue a couple of weeks ago (but with TTL and QPid).

First the JMS is not Strict about this :

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.

So, what you see is actually normal.

As a work-around you can use the Resequencer pattern if it fits your case.

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

Here is another discussion on this subject:

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

0
votes

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, e.g.,

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

To disable it, tcp://0.0.0.0:61616?jms.messagePrioritySupported=false

So you do not require to use Camel (if you want to avoid complication)