blob: a36a32c01d528857ee3e3544ff9586a090b08e42 [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>Non-Destructive Queues</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>Non-Destructive Queues</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="#limiting-the-size-of-the-queue">1. Limiting the Size of the Queue</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>When a consumer attaches to a queue, the normal behaviour is that messages are sent to that consumer are acquired exclusively by that consumer, and when the consumer acknowledges them, the messages are removed from the queue.</p>
</div>
<div class="paragraph">
<p>Another common pattern is to have queue "browsers" which send all messages to the browser, but do not prevent other consumers from receiving the messages, and do not remove them from the queue when the browser is done with them.
Such a browser is an instance of a "non-destructive" consumer.</p>
</div>
<div class="paragraph">
<p>If every consumer on a queue is non destructive then we can obtain some interesting behaviours.
In the case of a <a href="last-value-queues.html#last-value-queues">last value queue</a> then the queue will always contain the most up to date value for every key.</p>
</div>
<div class="paragraph">
<p>A queue can be created to enforce all consumers are non-destructive using the following queue configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight nowrap"><code data-lang="xml"><span class="nt">&lt;address</span> <span class="na">name=</span><span class="s">"foo.bar"</span><span class="nt">&gt;</span>
<span class="nt">&lt;multicast&gt;</span>
<span class="nt">&lt;queue</span> <span class="na">name=</span><span class="s">"orders1"</span> <span class="na">non-destructive=</span><span class="s">"true"</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;/multicast&gt;</span>
<span class="nt">&lt;/address&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Or on auto-create when using the JMS client 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?non-destructive=true"</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?non-destructive=true"</span><span class="o">);</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Also the default for all queues under and address can be defaulted using the <code>address-setting</code> configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight nowrap"><code data-lang="xml"><span class="nt">&lt;address-setting</span> <span class="na">match=</span><span class="s">"nonDestructiveQueue"</span><span class="nt">&gt;</span>
<span class="nt">&lt;default-non-destructive&gt;</span>true<span class="nt">&lt;/default-non-destructive&gt;</span>
<span class="nt">&lt;/address-setting&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>By default, <code>default-non-destructive</code> is <code>false</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="limiting-the-size-of-the-queue"><a class="anchor" href="#limiting-the-size-of-the-queue"></a><a class="link" href="#limiting-the-size-of-the-queue">1. Limiting the Size of the Queue</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>For queues other than last-value queues, having only non-destructive consumers could mean that messages would never get deleted, leaving the queue to grow without constraint.
To prevent this you can use the ability to set a default <code>expiry-delay</code>.
See <a href="message-expiry.html#configuring-expiry-delay">expiry-delay</a> for more details on this.
You could also use a <a href="ring-queues.html#ring-queue">ring queue</a>.</p>
</div>
</div>
</div>
</div>
</body>
</html>