blob: 7aa607eb28d334c4287b2222aaf99b5cc148c2ff [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>Extra Acknowledge Modes</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>Extra Acknowledge Modes</h1>
<div id="toc" class="toc2">
<div id="toctitle"><a href="index.html">User Manual for 2.32.0</a></div>
<ul class="sectlevel1">
<li><a href="#using-pre_acknowledge">1. Using PRE_ACKNOWLEDGE</a></li>
<li><a href="#individual-acknowledge">2. Individual Acknowledge</a></li>
<li><a href="#example">3. Example</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>JMS specifies 3 acknowledgement modes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>AUTO_ACKNOWLEDGE</code></p>
</li>
<li>
<p><code>CLIENT_ACKNOWLEDGE</code></p>
</li>
<li>
<p><code>DUPS_OK_ACKNOWLEDGE</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Apache ActiveMQ Artemis supports two additional modes: <code>PRE_ACKNOWLEDGE</code> and <code>INDIVIDUAL_ACKNOWLEDGE</code></p>
</div>
<div class="paragraph">
<p>In some cases you can afford to lose messages in event of failure, so it would make sense to acknowledge the message on the server <em>before</em> delivering it to the client.</p>
</div>
<div class="paragraph">
<p>This extra mode is supported by Apache ActiveMQ Artemis and will call it <em>pre-acknowledge</em> mode.</p>
</div>
<div class="paragraph">
<p>The disadvantage of acknowledging on the server before delivery is that the message will be lost if the system crashes <em>after</em> acknowledging the message on the server but <em>before</em> it is delivered to the client.
In that case, the message is lost and will not be recovered when the system restart.</p>
</div>
<div class="paragraph">
<p>Depending on your messaging case, <code>preAcknowledgement</code> mode can avoid extra network traffic and CPU at the cost of coping with message loss.</p>
</div>
<div class="paragraph">
<p>An example of a use case for pre-acknowledgement is for stock price update messages.
With these messages it might be reasonable to lose a message in event of crash, since the next price update message will arrive soon, overriding the previous price.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Please note, that if you use pre-acknowledge mode, then you will lose transactional semantics for messages being consumed, since clearly they are being acknowledged first on the server, not when you commit the transaction.
This may be stating the obvious but we like to be clear on these things to avoid confusion!</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="using-pre_acknowledge"><a class="anchor" href="#using-pre_acknowledge"></a><a class="link" href="#using-pre_acknowledge">1. Using PRE_ACKNOWLEDGE</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This can be configured by setting the boolean URL parameter <code>preAcknowledge</code> to <code>true</code>.</p>
</div>
<div class="paragraph">
<p>Alternatively, when using the JMS API, create a JMS Session with the <code>ActiveMQSession.PRE_ACKNOWLEDGE</code> constant.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight nowrap"><code data-lang="java"><span class="c1">// messages will be acknowledge on the server *before* being delivered to the client</span>
<span class="nc">Session</span> <span class="n">session</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="na">createSession</span><span class="o">(</span><span class="kc">false</span><span class="o">,</span> <span class="nc">ActiveMQJMSConstants</span><span class="o">.</span><span class="na">PRE_ACKNOWLEDGE</span><span class="o">);</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="individual-acknowledge"><a class="anchor" href="#individual-acknowledge"></a><a class="link" href="#individual-acknowledge">2. Individual Acknowledge</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>A valid use-case for individual acknowledgement would be when you need to have your own scheduling and you don&#8217;t know when your message processing will be finished.
You should prefer having one consumer per thread worker but this is not possible in some circumstances depending on how complex is your processing.
For that you can use the individual acknowledgement.</p>
</div>
<div class="paragraph">
<p>You basically setup Individual ACK by creating a session with the acknowledge mode with <code>ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE</code>.
Individual ACK inherits all the semantics from Client Acknowledge, with the exception the message is individually acked.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Please note, that to avoid confusion on MDB processing, Individual ACKNOWLEDGE is not supported through MDBs (or the inbound resource adapter).
this is because you have to finish the process of your message inside the MDB.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="example"><a class="anchor" href="#example"></a><a class="link" href="#example">3. Example</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>See the <a href="examples.html#pre-acknowledge">Pre-acknowledge Example</a> which shows how to use pre-acknowledgement mode with JMS.</p>
</div>
</div>
</div>
</div>
</body>
</html>