blob: 863fd56284e574255bc306181a2002343975ea99 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.18">
<link rel="icon" type="image/png" href="images/favicon.png">
<title>Consumer Priority</title>
<link rel="stylesheet" href="css/asciidoctor.css">
<link rel="stylesheet" href="css/font-awesome.css">
<link rel="stylesheet" href="css/rouge-github.css">
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>Consumer Priority</h1>
<div id="toc" class="toc2">
<div id="toctitle"><a href="index.html">User Manual for 2.33.0</a></div>
<ul class="sectlevel1">
<li><a href="#core">1. Core</a>
<ul class="sectlevel2">
<li><a href="#jms-example">1.1. JMS Example</a></li>
</ul>
</li>
<li><a href="#openwire">2. OpenWire</a>
<ul class="sectlevel2">
<li><a href="#jms-example-2">2.1. JMS Example</a></li>
</ul>
</li>
<li><a href="#amqp">3. AMQP</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Consumer priorities allow you to ensure that high priority consumers receive messages while they are active.</p>
</div>
<div class="paragraph">
<p>Normally, active consumers connected to a queue receive messages from it in a round-robin fashion.
When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority.</p>
</div>
<div class="paragraph">
<p>Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).</p>
</div>
<div class="paragraph">
<p>Where a consumer does not set, the default priority <strong>0</strong> is used.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="core"><a class="anchor" href="#core"></a><a class="link" href="#core">1. Core</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="jms-example"><a class="anchor" href="#jms-example"></a><a class="link" href="#jms-example">1.1. JMS Example</a></h3>
<div class="paragraph">
<p>When using the JMS Client you can set the priority to be used, by using address parameters when creating the destination used by the consumer.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight nowrap"><code data-lang="java"><span class="nc">Queue</span> <span class="n">queue</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">createQueue</span><span class="o">(</span><span class="s">"my.destination.name?consumer-priority=50"</span><span class="o">);</span>
<span class="nc">Topic</span> <span class="n">topic</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">createTopic</span><span class="o">(</span><span class="s">"my.destination.name?consumer-priority=50"</span><span class="o">);</span>
<span class="n">consumer</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">createConsumer</span><span class="o">(</span><span class="n">queue</span><span class="o">);</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The range of priority values is -2<sup>31</sup> to 2<sup>31</sup>-1.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="openwire"><a class="anchor" href="#openwire"></a><a class="link" href="#openwire">2. OpenWire</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="jms-example-2"><a class="anchor" href="#jms-example-2"></a><a class="link" href="#jms-example-2">2.1. JMS Example</a></h3>
<div class="paragraph">
<p>The priority for a consumer is set using Destination Options as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight nowrap"><code data-lang="java"><span class="n">queue</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ActiveMQQueue</span><span class="o">(</span><span class="s">"TEST.QUEUE?consumer.priority=10"</span><span class="o">);</span>
<span class="n">consumer</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">createConsumer</span><span class="o">(</span><span class="n">queue</span><span class="o">);</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Because of the limitation of OpenWire, the range of priority values is: 0 to 127.
The highest priority is 127.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="amqp"><a class="anchor" href="#amqp"></a><a class="link" href="#amqp">3. AMQP</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>In AMQP 1.0 the priority of the consumer is set in the properties map of the attach frame where the broker side of the link represents the sending side of the link.</p>
</div>
<div class="paragraph">
<p>The key for the entry must be the literal string priority, and the value of the entry must be an integral number in the range -2<sup>31</sup> to 2<sup>31</sup>-1.</p>
</div>
</div>
</div>
</div>
</body>
</html>