How can I support priority queues?

Use Message Priority

A common requirement is to support priority consumption; so high priority messages are consumed before low priority.

In version 5.4 priority queues are supported. Both the message cursors and the message stores (KahaDB and JDBC) support message priority. The support is disabled by default so it needs to be be enabled using Per Destination Policies through xml configuration, in the example below, 'prioritizedMessages' is enabled for all queues.

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

The full range of priority values (0-9) are supported by the JDBC message store. For KahaDB three priority levels are supported, Low (<5), Default (=5) and High (>5).

Alternative strategies

Use Selectors

You can have say 100 consumers using a selector to find the high priority stuff

JMSPriority > 6

then have 50 consumers doing average or above

JMSPriority >= 4

Then say 10 consumers consuming all messages (so all priorities). Then this way you'll have a pool of threads always processing high priority messages - giving you very efficient priority based dispatching of messages without ActiveMQ having to batch up messages and reorder them before dispatching them.

Use Resequencer

You can reorder messages on some input queue A and send them to queue B in sorted order to avoid having to change your clients. This avoids the need to use selectors in your application as shown above.

To do this use the Resequencer from the Enterprise Integration Patterns

© 2004-2011 The Apache Software Foundation.
Apache ActiveMQ, ActiveMQ, Apache, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram