blob: 23e5c3c3b7768daf69ef72c8cbdbc459bb9f9b65 [file] [log] [blame]
<div class="wiki-content maincontent"><h3 id="ConsumerPriority-Background">Background</h3><p>As well as having a pluggable dispatch policy e.g. round robin, ActiveMQ also supports consumer priorities. This allows us to weight consumers to optimize network hops. For example, you typically want a broker to send messages to regular JMS consumers rather than to other brokers; there's no need to make unnecessary broker-to-broker hops if there are available consumers.</p><h3 id="ConsumerPriority-Example">Example</h3><p>The priority for a consumer is set using <a shape="rect" href="destination-options.xml">Destination Options</a> as follows:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[queue = new ActiveMQQueue(&quot;TEST.QUEUE?consumer.priority=10&quot;);
consumer = session.createConsumer(queue);
]]></script>
</div></div><p>The range of priority values is: <strong><code>0</code></strong> to <strong><code>127</code></strong>. The highest priority is <strong><code>127</code></strong>. The default priority is <strong><code>0</code></strong>.</p><p>The broker orders a queue's consumers according to their priorities, dispatching messages to the highest priority consumers first. Once a particular consumer's prefetch buffer is full the broker will start dispatching messages to the consumer with the next lowest priority whose prefetch buffer is not full.</p></div>