Author: buildbot
Date: Fri Jan  6 15:19:46 2017
New Revision: 1004265

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/oncompletion.html

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/camel/content/oncompletion.html
==============================================================================
--- websites/production/camel/content/oncompletion.html (original)
+++ websites/production/camel/content/oncompletion.html Fri Jan  6 15:19:46 2017
@@ -86,7 +86,7 @@
        <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 
id="OnCompletion-OnCompletion">OnCompletion</h2><p>Camel has this concept of a 
Unit of Work that encompass the <a shape="rect" 
href="exchange.html">Exchange</a>. The unit of work among others supports 
synchronization callbacks that are invoked when the <a shape="rect" 
href="exchange.html">Exchange</a> is complete. The callback API is defined in 
<code>org.apache.camel.spi.Synchronization</code>. From <strong>Camel 
2.14</strong> onwards we have an extended synchronization 
<code>org.apache.camel.spi.SynchronizationRouteAware</code>&#160;that have 
callbacks for route events.</p><div class="confluence-information-macro 
confluence-information-macro-tip"><p class="title">Getting the 
UnitOfWork</p><span class="aui-icon aui-icon-small aui-iconfont-approve 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>You can get hold of the 
<code>org.apache.camel.spi.UnitOfWork</code> from 
<code>org.apache.camel.Exchange<
 /code> with the method <code>getUnitOfWork()</code>.</p></div></div><p>In 
Camel 2.0 we have added DSL for these callbacks using the new 
<strong>onCompletion</strong> DSL name.</p><p><strong>onCompletion</strong> 
supports the following features:</p><ul class="alternate"><li>scope: global 
and/or per route (route scope override all global scope)</li><li><span 
style="line-height: 1.4285715;">multiple global scope</span></li><li>triggered 
either always, only if completed with success, or only if 
failed</li><li><code>onWhen</code> predicate to only trigger in certain 
situations</li><li><strong>Camel 2.14:</strong> mode: to define whether to run 
either before or after route consumer writes response back to callee (if its 
InOut)</li><li><strong>Camel 2.14: </strong>whether to run async or sync (use a 
thread pool or not)</li></ul><p>From&#160;<strong>Camel 2.14</strong> onwards 
the onCompletion has been modified to support running the completion task in 
either synchronous or asynchronous mod
 e (using a thread pool) and also whether to run before or after the route 
consumer is done. The reason is to give more flexibility. For example to 
specify to run synchronous and before the route consumer is done, which allows 
to modify the exchange before the consumer writes back any response to the 
callee. You can use this to for example add customer headers, or send to a log 
to log the response message, etc.</p><div class="confluence-information-macro 
confluence-information-macro-information"><p class="title">Changes from Camel 
2.14 onwards</p><span class="aui-icon aui-icon-small aui-iconfont-info 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>The onCompletion has changed 
defaults and behavior from Camel 2.14 onwards. It now runs</p><ul 
style="list-style-type: square;"><li>Runs synchronously without any thread 
pool</li></ul><p>In Camel 2.13 the defaults were</p><ul><li>Runs asynchronous 
using a thread pool</li></ul></div></div><div clas
 s="confluence-information-macro confluence-information-macro-information"><p 
class="title">Camel 2.13 or older - On completion runs in separate 
thread</p><span class="aui-icon aui-icon-small aui-iconfont-info 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>The <strong>onCompletion</strong> 
runs in a separate thread in parallel with the original route. It is therefore 
not intended to influence the outcome of the original route. The idea for on 
completion is to spin off a new thread to eg send logs to a central log 
database, send an email, send alterts to a monitoring system, store a copy of 
the result message etc.<br clear="none"> Therefore if you want to do some work 
that influence the original route, then do <strong>not</strong> use 
<strong>onCompletion</strong> for that. Notice: if you use the 
<code>UnitOfWork</code> API as mentioned in the top of this page, then you can 
register a <code>Synchronization</code> callback on the <a shape="r
 ect" href="exchange.html">Exchange</a> which is executed in the original 
route. That way allows you to do some custom code when the route is completed; 
this is how custom components can enlist on completion services which they 
need, eg the <a shape="rect" href="file2.html">File</a> component does that for 
work that moves/deletes the original file etc.</p></div></div><h3 
id="OnCompletion-onCompletionwithroutescope">onCompletion with route 
scope</h3><p>The <strong>onCompletion</strong> DSL allows you to add custom 
routes/processors when the original <a shape="rect" 
href="exchange.html">Exchange</a> is complete. Camel spin off a copy of the <a 
shape="rect" href="exchange.html">Exchange</a> and routes it in a separate 
thread, kinda like a <a shape="rect" href="wire-tap.html">Wire Tap</a>. This 
allows the original thread to continue while the <strong>onCompletion</strong> 
route is running concurrently. We decided for this model as we did not want the 
<strong>onCompletion</strong> route t
 o interfere with the original route.</p><div 
class="confluence-information-macro confluence-information-macro-note"><p 
class="title">Only 1 onCompletion supported by route scope</p><span 
class="aui-icon aui-icon-small aui-iconfont-warning 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>You can only have 1 onCompletion 
in a route. Only at context scoped level you can have multiple. And notice that 
when you use a route scoped onCompletion then any context scoped are disabled 
for that given route.</p></div></div><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><h2 
id="OnCompletion-OnCompletion">OnCompletion</h2><p>Camel has this concept of a 
Unit of Work that encompass the <a shape="rect" 
href="exchange.html">Exchange</a>. The unit of work among others supports 
synchronization callbacks that are invoked when the <a shape="rect" 
href="exchange.html">Exchange</a> is complete. The callback API is defined in 
<strong><code>org.apache.camel.spi.Synchronization</code></strong>. From 
<strong>Camel 2.14</strong>: we have an extended synchronization 
<strong><code>org.apache.camel.spi.SynchronizationRouteAware</code></strong>&#160;that
 have callbacks for route events.</p><div class="confluence-information-macro 
confluence-information-macro-tip"><p class="title">Getting the 
UnitOfWork</p><span class="aui-icon aui-icon-small aui-iconfont-approve 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>You can get hold of the 
<strong><code>org.apache.camel.spi.UnitOfWork</code></s
 trong> from <strong><code>org.apache.camel.Exchange</code></strong> with the 
method <strong><code>getUnitOfWork()</code></strong>.</p></div></div><p>In 
Camel 2.0 we have added DSL for these callbacks using the 
new&#160;<strong><code>onCompletion</code></strong> DSL 
name.</p><p><strong><code>onCompletion</code></strong> supports the following 
features:</p><ul class="alternate"><li>Scope: global and/or per route (route 
scope override all global scope).</li><li><span style="line-height: 
1.4285715;">Multiple global scope.</span></li><li>Triggered either always, only 
if completed with success, or only if 
failed.</li><li><strong><code>onWhen</code></strong> predicate to only trigger 
in certain situations.</li><li><strong>Camel 2.14:</strong> Mode: to define 
whether to run either before or after route consumer writes response back to 
callee (if its <strong><code>InOut</code></strong>).</li><li><strong>Camel 
2.14: </strong>Whether to run async or sync (use a thread pool or 
not).</li></ul><p
 >From&#160;<strong>Camel 
 >2.14</strong>:&#160;<strong><code>onCompletion</code></strong> has been 
 >modified to support running the completion task in either synchronous or 
 >asynchronous mode (using a thread pool) and also whether to run before or 
 >after the route consumer is done. The reason is to give more flexibility. For 
 >example to specify to run synchronous and before the route consumer is done, 
 >which allows to modify the exchange before the consumer writes back any 
 >response to the callee. You can use this to for example add customer headers, 
 >or send to a log to log the response message, etc.</p><div 
 >class="confluence-information-macro 
 >confluence-information-macro-information"><p class="title">Changes from Camel 
 >2.14 onwards</p><span class="aui-icon aui-icon-small aui-iconfont-info 
 >confluence-information-macro-icon"></span><div 
 >class="confluence-information-macro-body"><p>The&#160;<strong><code>onCompletion</code></strong>
 > has changed defaults and behavior from Camel 2.14: it now ru
 ns</p><ul style="list-style-type: square;"><li>Runs synchronously without any 
thread pool</li></ul><p>In Camel 2.13 the defaults were</p><ul><li>Runs 
asynchronous using a thread pool</li></ul></div></div><div 
class="confluence-information-macro 
confluence-information-macro-information"><p class="title">Camel 2.13 or older 
- On completion runs in separate thread</p><span class="aui-icon aui-icon-small 
aui-iconfont-info confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>The&#160;<strong><code>onCompletion</code></strong>
 runs in a separate thread in parallel with the original route. It is therefore 
not intended to influence the outcome of the original route. The idea for on 
completion is to spin off a new thread to e.g., send logs to a central log 
database, send an email, send alerts to a monitoring system, store a copy of 
the result message etc.</p><p>Therefore if you want to do some work that 
influence the original route, then do <strong>not<
 /strong> use&#160;<strong><code>onCompletion</code></strong> for that. 
</p><div class="confluence-information-macro 
confluence-information-macro-tip"><span class="aui-icon aui-icon-small 
aui-iconfont-approve confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body">If you use the 
<strong><code>UnitOfWork</code></strong> API as mentioned in the top of this 
page, then you can register a <strong><code>Synchronization</code></strong> 
callback on the <a shape="rect" href="exchange.html">Exchange</a> which is 
executed in the original route. That way allows you to do some custom code when 
the route is completed; this is how custom components can enlist on completion 
services which they need, e.g., the <a shape="rect" href="file2.html">File</a> 
component does that for work that moves/deletes the original file 
etc.</div></div></div></div><h3 
id="OnCompletion-onCompletionWithRouteScope"><code>onCompletion</code> With 
Route Scope</h3><p>The&#160;<strong><code>onC
 ompletion</code></strong> DSL allows you to add custom routes/processors when 
the original <a shape="rect" href="exchange.html">Exchange</a> is complete. 
Camel spin off a copy of the <a shape="rect" href="exchange.html">Exchange</a> 
and routes it in a separate thread, kinda like a <a shape="rect" 
href="wire-tap.html">Wire Tap</a>. This allows the original thread to continue 
while the <strong><code>onCompletion</code></strong> route is running 
concurrently. We decided for this model as we did not want 
the&#160;<strong><code>onCompletion</code></strong> route to interfere with the 
original route.</p><div class="confluence-information-macro 
confluence-information-macro-note"><p class="title">Only one onCompletion 
supported by route scope</p><span class="aui-icon aui-icon-small 
aui-iconfont-warning confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>You can only have one 
<strong><code>onCompletion</code></strong> clause per route. At context scope
 d level it's possible to have many. And notice that when you use a route 
scoped&#160;<strong><code>onCompletion</code></strong> then any context scoped 
are disabled for that given route.</p></div></div><p></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[
 from(&quot;direct:start&quot;)
     .onCompletion()
@@ -100,7 +100,7 @@ from(&quot;direct:start&quot;)
     .process(new MyProcessor())
     .to(&quot;mock:result&quot;);
 ]]></script>
-</div></div><p>By default the <strong>onCompletion</strong> will be triggered 
when the <a shape="rect" href="exchange.html">Exchange</a> is complete and 
regardless if the <a shape="rect" href="exchange.html">Exchange</a> completed 
with success or with an failure (such as an Exception was thrown). You can 
limit the trigger to only occur <code>onCompleteOnly</code> or by 
<code>onFailureOnly</code> as shown below:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div>By default the&#160;<strong><code>onCompletion</code></strong> 
will be triggered when the <a shape="rect" href="exchange.html">Exchange</a> is 
complete and regardless if the <a shape="rect" 
href="exchange.html">Exchange</a> completed with success or with an failure 
(such as an Exception was thrown). You can limit the trigger to only occur 
<strong><code>onCompleteOnly</code></strong> or by 
<strong><code>onFailureOnly</code></strong> as shown below:<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[
 from(&quot;direct:start&quot;)
     // here we qualify onCompletion to only invoke when the exchange failed 
(exception or FAULT body)
@@ -113,7 +113,7 @@ from(&quot;direct:start&quot;)
     .process(new MyProcessor())
     .to(&quot;mock:result&quot;);
 ]]></script>
-</div></div><p>You can identify if the <a shape="rect" 
href="exchange.html">Exchange</a> is an <strong>onCompletion</strong> <a 
shape="rect" href="exchange.html">Exchange</a> as Camel will add the property 
<code>Exchange.ON_COMPLETION</code> with a boolean value of <code>true</code> 
when it spin offs the <strong>onCompletion</strong> <a shape="rect" 
href="exchange.html">Exchange</a>.</p><h4 
id="OnCompletion-UsingonCompletionfromSpringDSL">Using onCompletion from Spring 
DSL</h4><p>The onCompletion is defined like this with Spring DSL:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+</div></div>You can identify if the <a shape="rect" 
href="exchange.html">Exchange</a> is 
an&#160;<strong><code>onCompletion</code></strong> <a shape="rect" 
href="exchange.html">Exchange</a> as Camel will add the property 
<strong><code>Exchange.ON_COMPLETION</code></strong> with a boolean value of 
<strong><code>true</code></strong> when it spin offs 
the&#160;<strong><code>onCompletion</code></strong> <a shape="rect" 
href="exchange.html">Exchange</a>.<h4 
id="OnCompletion-UsingonCompletionfromSpringDSL">Using&#160;<code>onCompletion</code>
 from Spring DSL</h4><p>The&#160;<strong><code>onCompletion</code></strong> is 
defined like this with Spring DSL:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
 &lt;route&gt;
     &lt;from uri=&quot;direct:start&quot;/&gt;
@@ -128,7 +128,7 @@ from(&quot;direct:start&quot;)
     &lt;to uri=&quot;mock:result&quot;/&gt;
 &lt;/route&gt;
 ]]></script>
-</div></div><p>And the <code>onCompleteOnly</code> and 
<code>onFailureOnly</code> is defined as a boolean attribute on the 
&lt;onCompletion&gt; tag so the failure example would be:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div>And the <strong><code>onCompleteOnly</code></strong> and 
<strong><code>onFailureOnly</code></strong> is defined as a boolean attribute 
on the&#160;<strong><code>&lt;onCompletion&gt;</code></strong> tag so the 
failure example would be:<div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
 <script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
 &lt;route&gt;
     &lt;from uri=&quot;direct:start&quot;/&gt;
@@ -142,7 +142,7 @@ from(&quot;direct:start&quot;)
     &lt;to uri=&quot;mock:result&quot;/&gt;
 &lt;/route&gt;
 ]]></script>
-</div></div><h3 id="OnCompletion-onCompletionwithglobalscope">onCompletion 
with global scope</h3><p>This works just like the route scope except from the 
fact that they are defined globally. An example below:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h3 
id="OnCompletion-onCompletionWithGlobalScope"><code>onCompletion</code> With 
Global Scope</h3><p>This works just like the route scope except from the fact 
that they are defined globally. An example below:</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[
 // define a global on completion that is invoked when the exchange is complete
 onCompletion().to(&quot;log:global&quot;).to(&quot;mock:sync&quot;);
@@ -151,7 +151,7 @@ from(&quot;direct:start&quot;)
     .process(new MyProcessor())
     .to(&quot;mock:result&quot;);
 ]]></script>
-</div></div><h4 id="OnCompletion-UsingonCompletionfromSpringDSL.1">Using 
onCompletion from Spring DSL</h4><p>This works just like the route scope except 
from the fact that they are defined globally. An example below:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+</div></div><h4 
id="OnCompletion-UsingonCompletionfromSpringDSL.1">Using&#160;<code>onCompletion</code>
 from Spring DSL</h4><p>This works just like the route scope except from the 
fact that they are defined globally. An example below:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
 &lt;!-- this is a global onCompletion route that is invoke when any exchange 
is complete
      as a kind of after callback --&gt;
@@ -166,7 +166,7 @@ from(&quot;direct:start&quot;)
     &lt;to uri=&quot;mock:result&quot;/&gt;
 &lt;/route&gt;
 ]]></script>
-</div></div><div class="confluence-information-macro 
confluence-information-macro-information"><p class="title">Route scope override 
Global scope</p><span class="aui-icon aui-icon-small aui-iconfont-info 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>If an 
<strong>onCompletion</strong> is defined in a route, it overrides 
<strong>all</strong> global scoped and thus its only the route scoped that are 
used. The globally scoped ones are never used.</p></div></div><h3 
id="OnCompletion-UsingonCompletionwithonWhenpredicate">Using onCompletion with 
onWhen predicate</h3><p>As other DSL in Camel you can attach a <a shape="rect" 
href="predicate.html">Predicate</a> to the <strong>onCompletion</strong> so it 
only triggers in certain conditions, when the predicate matches.<br 
clear="none"> For example to only trigger if the message body contains the word 
<code>Hello</code> we can do like:</p><div class="code panel pdl" 
style="border-width: 1px;"><div c
 lass="codeContent panelContent pdl">
+</div></div><div class="confluence-information-macro 
confluence-information-macro-information"><p class="title">Route scope override 
Global scope</p><span class="aui-icon aui-icon-small aui-iconfont-info 
confluence-information-macro-icon"></span><div 
class="confluence-information-macro-body"><p>If an 
<strong><code>onCompletion</code></strong> is defined in a route, it overrides 
<strong>all</strong> global scoped and thus its only the route scoped that are 
used. The globally scoped ones are never used.</p></div></div><h3 
id="OnCompletion-UsingonCompletionwithonWhenPredicate">Using&#160;<code>onCompletion</code>
 with&#160;<code>onWhen</code> Predicate</h3><p>As other DSL in Camel you can 
attach a <a shape="rect" href="predicate.html">Predicate</a> to 
the&#160;<strong><code>onCompletion</code></strong> so it only triggers in 
certain conditions, when the predicate matches. For example to only trigger if 
the message body contains the word <strong><code>Hello</code></strong> we can 
do lik
 e:</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[
 from(&quot;direct:start&quot;)
     .onCompletion().onWhen(body().contains(&quot;Hello&quot;))
@@ -180,34 +180,34 @@ from(&quot;direct:start&quot;)
     .to(&quot;log:original&quot;)
     .to(&quot;mock:result&quot;);
 ]]></script>
-</div></div><h3 
id="OnCompletion-UsingonCompletionwithorwithoutthreadpool">Using onCompletion 
with or without thread pool</h3><p><strong>Available as of Camel 
2.14</strong></p><p>OnCompletion will from Camel 2.14 onwards not use thread 
pool by default. To use thread pool then either set 
a&#160;<code>executorService</code> or set <code>parallelProcessing</code> to 
true.</p><p>For example in Java DSL do</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[                
onCompletion().parallelProcessing()
-                    .to(&quot;mock:before&quot;)
-                    .delay(1000)
-                    
.setBody(simple(&quot;OnComplete:${body}&quot;));]]></script>
-</div></div><p>And in XML DSL</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[      &lt;onCompletion 
parallelProcessing=&quot;true&quot;&gt;
-        &lt;to uri=&quot;before&quot;/&gt;
-        &lt;delay&gt;&lt;constant&gt;1000&lt;/constant&gt;&lt;/delay&gt;
-        
&lt;setBody&gt;&lt;simple&gt;OnComplete:${body}&lt;/simple&gt;&lt;/setBody&gt;
-      &lt;/onCompletion&gt;]]></script>
-</div></div><p>You can also refer to a specific <a shape="rect" 
href="threading-model.html">thread pool</a> to be used, using the 
executorServiceRef option</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[      &lt;onCompletion 
executorServiceRef=&quot;myThreadPool&quot;&gt;
-        &lt;to uri=&quot;before&quot;/&gt;
-        &lt;delay&gt;&lt;constant&gt;1000&lt;/constant&gt;&lt;/delay&gt;
-        
&lt;setBody&gt;&lt;simple&gt;OnComplete:${body}&lt;/simple&gt;&lt;/setBody&gt;
-      &lt;/onCompletion&gt;]]></script>
-</div></div><p>&#160;</p><h3 
id="OnCompletion-UsingonCompletiontorunbeforerouteconsumersendsbackresponsetocallee">Using
 onCompletion to run before route consumer sends back response to 
callee</h3><p><strong>Available as of Camel 2.14</strong></p><p>OnCompletion 
supports two modes</p><ul style="list-style-type: square;"><li>AfterConsumer - 
Default mode which runs after the consumer is done</li><li>BeforeConsumer - 
Runs before the consumer is done, and before the consumer writes back response 
to the callee</li></ul><p>The AfterConsumer mode is the default mode which is 
the same behavior as in older Camel releases.</p><p>The new BeforeConsumer mode 
is used to run onCompletion before the consumer writes its response back to the 
callee (if in InOut mode). This allows the onCompletion to modify the Exchange, 
such as adding special headers, or to log the Exchange as a response logger 
etc.</p><p>For example to always add a "created by" header you 
use&#160;<code>modeBeforeConsumer()</code> a
 s shown below:</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[    .onCompletion().modeBeforeConsumer()
-        .setHeader(&quot;createdBy&quot;, constant(&quot;Someone&quot;))
-    .end()]]></script>
-</div></div><p>&#160;</p><p>And in XML DSL you set the mode attribute to 
BeforeConsumer:</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[      &lt;onCompletion 
mode=&quot;BeforeConsumer&quot;&gt;
-        &lt;setHeader headerName=&quot;createdBy&quot;&gt;
-          &lt;constant&gt;Someone&lt;/constant&gt;
-        &lt;/setHeader&gt;
-      &lt;/onCompletion&gt;]]></script>
-</div></div><p>&#160;</p><h3 id="OnCompletion-SeeAlso">See Also</h3><ul 
class="alternate"><li>Unit of Work</li></ul></div>
+</div></div><h3 
id="OnCompletion-UsingonCompletionWithorWithoutaThreadpool">Using&#160;<code>onCompletion</code>
 With or Without a Threadpool</h3><p><strong>Available as of Camel 
2.14</strong></p><p><strong><code>onCompletion</code></strong> will from Camel 
2.14: not use thread pool by default. To use thread pool then either set 
a&#160;<strong><code>executorService</code></strong> or set 
<strong><code>parallelProcessing</code></strong> to 
<strong><code>true</code></strong>.</p><p>For example in Java DSL:</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[onCompletion().parallelProcessing()
+  .to(&quot;mock:before&quot;)
+  .delay(1000)
+  .setBody(simple(&quot;OnComplete:${body}&quot;));]]></script>
+</div></div><p>And in XML DSL:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;onCompletion 
parallelProcessing=&quot;true&quot;&gt;
+  &lt;to uri=&quot;before&quot;/&gt;
+  &lt;delay&gt;&lt;constant&gt;1000&lt;/constant&gt;&lt;/delay&gt;
+  
&lt;setBody&gt;&lt;simple&gt;OnComplete:${body}&lt;/simple&gt;&lt;/setBody&gt;
+&lt;/onCompletion&gt;]]></script>
+</div></div><p>You can also refer to a specific <a shape="rect" 
href="threading-model.html">thread pool</a> to be used, using 
the&#160;<strong><code>executorServiceRef</code></strong> option:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;onCompletion 
executorServiceRef=&quot;myThreadPool&quot;&gt;
+  &lt;to uri=&quot;before&quot;/&gt;
+  &lt;delay&gt;&lt;constant&gt;1000&lt;/constant&gt;&lt;/delay&gt;
+  
&lt;setBody&gt;&lt;simple&gt;OnComplete:${body}&lt;/simple&gt;&lt;/setBody&gt;
+&lt;/onCompletion&gt;]]></script>
+</div></div><p>&#160;</p><h3 
id="OnCompletion-UsingonCompletiontoRunBeforeRouteConsumerSendsBackResponsetoCallee">Using&#160;<code>onCompletion</code>
 to Run Before Route Consumer Sends Back Response to 
Callee</h3><p><strong>Available as of Camel 
2.14</strong></p><p><strong><code>onCompletion</code></strong> supports two 
modes</p><ul style="list-style-type: 
square;"><li><strong><code>AfterConsumer</code></strong> - Default mode which 
runs after the consumer is 
done.</li><li><strong><code>BeforeConsumer</code></strong> - Runs before the 
consumer is done, and before the consumer writes back response to the 
callee.</li></ul><p>The&#160;<strong><code>AfterConsumer</code></strong> mode 
is the default mode which is the same behavior as in older Camel 
releases.</p><p>The new&#160;<strong><code>BeforeConsumer</code></strong> mode 
is used to run&#160;<strong><code>onCompletion</code></strong> before the 
consumer writes its response back to the callee (if 
in&#160;<strong><code>InOut</code></s
 trong> mode). This allows the&#160;<strong><code>onCompletion</code></strong> 
to modify the Exchange, such as adding special headers, or to log the Exchange 
as a response logger etc.</p><p>For example to always add a "created by" header 
you use&#160;<strong><code>modeBeforeConsumer()</code></strong> as shown 
below:</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[.onCompletion().modeBeforeConsumer()
+  .setHeader(&quot;createdBy&quot;, constant(&quot;Someone&quot;))
+.end()]]></script>
+</div></div><p>&#160;</p><p>And in XML DSL you set the mode attribute to 
<strong><code>BeforeConsumer</code></strong>:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;onCompletion 
mode=&quot;BeforeConsumer&quot;&gt;
+  &lt;setHeader headerName=&quot;createdBy&quot;&gt;
+    &lt;constant&gt;Someone&lt;/constant&gt;
+  &lt;/setHeader&gt;
+&lt;/onCompletion&gt;]]></script>
+</div></div><h3 id="OnCompletion-SeeAlso">See Also</h3><ul 
class="alternate"><li>Unit of Work</li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">


Reply via email to