Modified: websites/production/camel/content/oncompletion.html
==============================================================================
--- websites/production/camel/content/oncompletion.html (original)
+++ websites/production/camel/content/oncompletion.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: OnCompletion
@@ -86,128 +75,24 @@
<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
<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> 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 <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 <strong>Camel
>2.14</strong>: <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 <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 <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 <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 <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 <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 <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("direct:start")
- .onCompletion()
- // this route is only invoked when the original route is complete as a
kind
- // of completion callback
- .to("log:sync")
- .to("mock:sync")
- // must use end to denote the end of the onCompletion route
- .end()
- // here the original route contiues
- .process(new MyProcessor())
- .to("mock:result");
-]]></script>
-</div></div>By default the <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("direct:start")
- // here we qualify onCompletion to only invoke when the exchange failed
(exception or FAULT body)
- .onCompletion().onFailureOnly()
- .to("log:sync")
- .to("mock:sync")
- // must use end to denote the end of the onCompletion route
- .end()
- // here the original route continues
- .process(new MyProcessor())
- .to("mock:result");
-]]></script>
-</div></div>You can identify if the <a shape="rect"
href="exchange.html">Exchange</a> is
an <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 <strong><code>onCompletion</code></strong> <a shape="rect"
href="exchange.html">Exchange</a>.<h4
id="OnCompletion-UsingonCompletionfromSpringDSL">Using <code>onCompletion</code>
from Spring DSL</h4><p>The <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[
-<route>
- <from uri="direct:start"/>
- <!-- this onCompletion block will only be executed when the exchange is
done being routed -->
- <!-- this callback is always triggered even if the exchange failed
-->
- <onCompletion>
- <!-- so this is a kinda like an after completion callback -->
- <to uri="log:sync"/>
- <to uri="mock:sync"/>
- </onCompletion>
- <process ref="myProcessor"/>
- <to uri="mock:result"/>
-</route>
-]]></script>
-</div></div>And the <strong><code>onCompleteOnly</code></strong> and
<strong><code>onFailureOnly</code></strong> is defined as a boolean attribute
on the <strong><code><onCompletion></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[
-<route>
- <from uri="direct:start"/>
- <!-- this onCompletion block will only be executed when the exchange is
done being routed -->
- <!-- this callback is only triggered when the exchange failed, as we
have onFailure=true -->
- <onCompletion onFailureOnly="true">
- <to uri="log:sync"/>
- <to uri="mock:sync"/>
- </onCompletion>
- <process ref="myProcessor"/>
- <to uri="mock:result"/>
-</route>
-]]></script>
-</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("log:global").to("mock:sync");
-
-from("direct:start")
- .process(new MyProcessor())
- .to("mock:result");
-]]></script>
-</div></div><h4
id="OnCompletion-UsingonCompletionfromSpringDSL.1">Using <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[
-<!-- this is a global onCompletion route that is invoke when any exchange
is complete
- as a kind of after callback -->
-<onCompletion>
- <to uri="log:global"/>
- <to uri="mock:sync"/>
-</onCompletion>
-
-<route>
- <from uri="direct:start"/>
- <process ref="myProcessor"/>
- <to uri="mock:result"/>
-</route>
-]]></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><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 <code>onCompletion</code>
with <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 <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("direct:start")
- .onCompletion().onWhen(body().contains("Hello"))
- // this route is only invoked when the original route is complete as a
kind
- // of completion callback. And also only if the onWhen predicate is
true
- .to("log:sync")
- .to("mock:sync")
- // must use end to denote the end of the onCompletion route
- .end()
- // here the original route contiues
- .to("log:original")
- .to("mock:result");
-]]></script>
-</div></div><h3
id="OnCompletion-UsingonCompletionWithorWithoutaThreadpool">Using <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 <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("mock:before")
+<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> that
have callbacks for route events.</p><parameter ac:name="title">Getting the
UnitOfWork</parameter><rich-text-body><p>You can get hold of the
<strong><code>org.apache.camel.spi.UnitOfWork</code></strong> from
<strong><code>org.apache.camel.Exchange</code></strong> with the method
<strong><code>getUnitOfWork()</code></strong>.</p></rich-text-body><p>In Camel
2.0 we have added DSL for
these callbacks using the new <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 <strong>Camel
2.14</strong>: <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><parameter ac:name="title">Changes from
Camel 2.14
onwards</parameter><rich-text-body><p>The <strong><code>onCompletion</code></strong>
has changed defaults and behavior from Camel 2.14: 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></rich-text-body><parameter ac:name="title">Camel
2.13 or older - On completion runs in separate
thread</parameter><rich-text-body><p>The <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 <strong><code>onCompletion</code></strong> for that.
> </p><rich-text-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">F
ile</a> component does that for work that moves/deletes the original file
etc.</rich-text-body></rich-text-body><h3
id="OnCompletion-onCompletionWithRouteScope"><code>onCompletion</code> With
Route Scope</h3><p>The <strong><code>onCompletion</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 <strong><code>onCompletion</code></strong> route to interfere with the
original route.</p><parameter ac:name="title">Only one onCompletion supported
by route scope</parameter><rich-text-body><p>You can only have one
<strong><code>onCompletion</c
ode></strong> clause per route. At context scoped level it's possible to have
many. And notice that when you use a route
scoped <strong><code>onCompletion</code></strong> then any context scoped
are disabled for that given
route.</p></rich-text-body><p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionTest.java}</plain-text-body>By
default the <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:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionOnFailureOnlyTes
t.java}</plain-text-body>You can identify if the <a shape="rect"
href="exchange.html">Exchange</a> is
an <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 <strong><code>onCompletion</code></strong> <a shape="rect"
href="exchange.html">Exchange</a>.</p><h4
id="OnCompletion-UsingonCompletionfromSpringDSL">Using <code>onCompletion</code>
from Spring DSL</h4><p>The <strong><code>onCompletion</code></strong> is
defined like this with Spring
DSL:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringOnCompletionTest.xml}</plain-text-body>And
the <strong><code>onCompleteOnly</code></strong> and
<strong><code>onFailureOnly</code></strong> is defined as a boolean attribute
on the 
;<strong><code><onCompletion></code></strong> tag so the failure example
would
be:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringOnCompletionOnFailureOnlyTest.xml}</plain-text-body></p><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:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionGlobalTest.java}</plain-text-body></p><h4
id="OnCompletion-UsingonCompletionfromSpringDSL.1">Using <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:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring
/processor/SpringOnCompletionGlobalTest.xml}</plain-text-body></p><parameter
ac:name="title">Route scope override Global
scope</parameter><rich-text-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></rich-text-body><h3
id="OnCompletion-UsingonCompletionwithonWhenPredicate">Using <code>onCompletion</code>
with <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 <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
like:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionWhenTest.j
ava}</plain-text-body></p><h3
id="OnCompletion-UsingonCompletionWithorWithoutaThreadpool">Using <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 <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><parameter
ac:name="language">java</parameter><plain-text-body>onCompletion().parallelProcessing()
+ .to("mock:before")
.delay(1000)
- .setBody(simple("OnComplete:${body}"));]]></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[<onCompletion
parallelProcessing="true">
- <to uri="before"/>
+ .setBody(simple("OnComplete:${body}"));</plain-text-body><p>And in XML
DSL:</p><parameter
ac:name="language">xml</parameter><plain-text-body><onCompletion
parallelProcessing="true">
+ <to uri="before"/>
<delay><constant>1000</constant></delay>
<setBody><simple>OnComplete:${body}</simple></setBody>
-</onCompletion>]]></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 <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[<onCompletion
executorServiceRef="myThreadPool">
- <to uri="before"/>
+</onCompletion></plain-text-body><p>You can also refer to a specific <a
shape="rect" href="threading-model.html">thread pool</a> to be used, using
the <strong><code>executorServiceRef</code></strong> option:</p><parameter
ac:name="language">xml</parameter><plain-text-body><onCompletion
executorServiceRef="myThreadPool">
+ <to uri="before"/>
<delay><constant>1000</constant></delay>
<setBody><simple>OnComplete:${body}</simple></setBody>
-</onCompletion>]]></script>
-</div></div><p> </p><h3
id="OnCompletion-UsingonCompletiontoRunBeforeRouteConsumerSendsBackResponsetoCallee">Using <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 <strong><code>AfterConsumer</code></strong> mode
is the default mode which is the same behavior as in older Camel
releases.</p><p>The new <strong><code>BeforeConsumer</code></strong> mode
is used to run <strong><code>onCompletion</code></strong> before the
consumer writes its response back to the callee (if
in <strong><code>InOut</code></s
trong> mode). This allows the <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 <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("createdBy", constant("Someone"))
-.end()]]></script>
-</div></div><p> </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[<onCompletion
mode="BeforeConsumer">
- <setHeader headerName="createdBy">
+</onCompletion></plain-text-body><p> </p><h3
id="OnCompletion-UsingonCompletiontoRunBeforeRouteConsumerSendsBackResponsetoCallee">Using <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 <strong><code>AfterConsumer</code></strong> mode
is the default mode which is the same behavior as in older Camel
releases.</p><p>The new <strong><code>BeforeConsumer</code></strong> mode
is used to run <strong><code>onCompletion</code></strong> before the
consumer writes its response back to the callee (if in <s
trong><code>InOut</code></strong> mode). This allows
the <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 <strong><code>modeBeforeConsumer()</code></strong> as shown
below:</p><parameter
ac:name="language">java</parameter><plain-text-body>.onCompletion().modeBeforeConsumer()
+ .setHeader("createdBy", constant("Someone"))
+.end()</plain-text-body><p> </p><p>And in XML DSL you set the mode
attribute to <strong><code>BeforeConsumer</code></strong>:</p><parameter
ac:name="language">xml</parameter><plain-text-body><onCompletion
mode="BeforeConsumer">
+ <setHeader headerName="createdBy">
<constant>Someone</constant>
</setHeader>
-</onCompletion>]]></script>
-</div></div><h3 id="OnCompletion-SeeAlso">See Also</h3><ul
class="alternate"><li>Unit of Work</li></ul></div>
+</onCompletion></plain-text-body><h3 id="OnCompletion-SeeAlso">See
Also</h3><ul class="alternate"><li>Unit of Work</li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/php.html
==============================================================================
--- websites/production/camel/content/php.html (original)
+++ websites/production/camel/content/php.html Fri Aug 25 08:22:01 2017
@@ -40,8 +40,6 @@
<link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
<script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
<script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
<script type="text/javascript">
SyntaxHighlighter.defaults['toolbar'] = false;
@@ -100,46 +98,19 @@
<p>For example you could use the <strong>php</strong> function to create an <a
shape="rect" href="predicate.html">Predicate</a> in a <a shape="rect"
href="message-filter.html">Message Filter</a> or as an <a shape="rect"
href="expression.html">Expression</a> for a <a shape="rect"
href="recipient-list.html">Recipient List</a></p>
-<h3 id="PHP-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </p><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</div></div><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Cam
elContext</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The Camel Context.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>context</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <strong><
code>resolve</code></strong> method to make it easier to use Camels <a
shape="rect" href="properties.html">Properties</a> component from scripts. See
further below for example.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message instead.</p></td></tr></tbody></tabl
e></div><p>See <a shape="rect" href="scripting-languages.html">Scripting
Languages</a> for the list of languages with explicit DSL support.</p><h3
id="PHP-PassingAdditionalArgumentstotheScriptingEngine">Passing Additional
Arguments to the <code>ScriptingEngine</code></h3><p><strong>Available
from Camel 2.8</strong></p><p>You can provide additional arguments to the
<strong><code>ScriptingEngine</code></strong> using a header on the Camel
message with the key
<strong><code>CamelScriptArguments</code></strong>.</p><p>Example:</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[
-public void testArgumentsExample() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(0);
- getMockEndpoint("mock:unmatched").expectedMessageCount(1);
-
- // additional arguments to ScriptEngine
- Map<String, Object> arguments = new HashMap<String, Object>();
- arguments.put("foo", "bar");
- arguments.put("baz", 7);
-
- // those additional arguments is provided as a header on the Camel Message
- template.sendBodyAndHeader("direct:start", "hello",
ScriptBuilder.ARGUMENTS, arguments);
-
- assertMockEndpointsSatisfied();
-}
-]]></script>
-</div></div><h3 id="PHP-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</code></strong>.</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[.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
-]]></script>
-</div></div><p>From <strong>Camel 2.9</strong>: you can now use the properties
function and the same example is simpler:</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[.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
-]]></script>
-</div></div><h3 id="PHP-LoadingScriptFromExternalResource">Loading Script From
External Resource</h3><p><strong>Available from Camel 2.11</strong></p><p>You
can externalize the script and have Camel load it from a resource such as
<strong><code>classpath:</code></strong>, <strong><code>file:</code></strong>,
or <strong><code>http:</code></strong>. This is done using the following
syntax: <strong><code>resource:scheme:location</code></strong> e.g. to refer to
a file on the classpath you can 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[.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
-]]></script>
-</div></div><h3 id="PHP-HowtoGettheResultfromMultipleStatementsScript">How to
Get the Result from Multiple Statements Script</h3><p><strong>Available from
Camel 2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: text; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[bar = "baz";
+<h3 id="PHP-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </p><rich-text-body>The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel
Context.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>context</code></p></td><td colspan=
"1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <strong><code>resolve</code></strong> method to make it easier
to use Camels <a shape="rect" href="properties.html">Properties</a> component
from scripts. See further below for example.</p></td></tr><tr><td colspan=
"1" rowspan="1" class="confluenceTd"><p><code>request</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message
instead.</p></td></tr></tbody></table></div><p>See <a shape="rect"
href="scripting-languages.html">Scripting Languages</a> for the list of
languages with explicit DSL support.</p><h3
id="PHP-PassingAdditionalArgumentstotheScriptingEngine">Pas
sing Additional Arguments to
the <code>ScriptingEngine</code></h3><p><strong>Available from Camel
2.8</strong></p><p>You can provide additional arguments to the
<strong><code>ScriptingEngine</code></strong> using a header on the Camel
message with the key
<strong><code>CamelScriptArguments</code></strong>.</p><p>Example:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptExpressionTest.java}</plain-text-body></p><h3
id="PHP-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</code></strong>.</p><plai
n-text-body>.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
+</plain-text-body><p>From <strong>Camel 2.9</strong>: you can now use the
properties function and the same example is simpler:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
+</plain-text-body><h3 id="PHP-LoadingScriptFromExternalResource">Loading
Script From External Resource</h3><p><strong>Available from Camel
2.11</strong></p><p>You can externalize the script and have Camel load it from
a resource such as <strong><code>classpath:</code></strong>,
<strong><code>file:</code></strong>, or <strong><code>http:</code></strong>.
This is done using the following syntax:
<strong><code>resource:scheme:location</code></strong> e.g. to refer to a file
on the classpath you can do:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
+</plain-text-body><h3
id="PHP-HowtoGettheResultfromMultipleStatementsScript">How to Get the Result
from Multiple Statements Script</h3><p><strong>Available from Camel
2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><parameter ac:name="language">text</parameter><plain-text-body>bar =
"baz";
# some other statements ...
# camel take the result value as the script evaluation result
result = body * 2 + 1
-]]></script>
-</div></div><p> </p><h3 id="PHP-Dependencies">Dependencies</h3><p>To use
scripting languages in your camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</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[<dependency>
+</plain-text-body><p> </p><h3
id="PHP-Dependencies">Dependencies</h3><p>To use scripting languages in your
camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>x.x.x</version>
</dependency>
-]]></script>
-</div></div></div>
+</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/pojo-messaging-example.html
==============================================================================
--- websites/production/camel/content/pojo-messaging-example.html (original)
+++ websites/production/camel/content/pojo-messaging-example.html Fri Aug 25
08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: POJO Messaging Example
@@ -102,81 +91,40 @@
<p>The <code>README.txt</code> states how to run the example from either Ant
or Maven.</p>
<p>Here's how to run it with Maven:</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[
+<plain-text-body>
mvn compile camel:run
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="POJOMessagingExample-Whatshappening?">Whats happening?</h3>
<p>When you start the example up you'll see a whole bunch of logs that won't
really mean anything to you <img class="emoticon emoticon-smile"
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/smile.png"
data-emoticon-name="smile" alt="(smile)"> The interesting stuff is happening
in the background. Here's a diagram of whats going on.</p>
-<p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image"
src="pojo-messaging-example.data/pojo-messaging.jpg"
data-image-src="/confluence/download/attachments/108577/pojo-messaging.jpg?version=1&modificationDate=1233062777000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="9645"
data-linked-resource-version="1" data-linked-resource-type="attachment"
data-linked-resource-default-alias="pojo-messaging.jpg"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/jpeg"
data-linked-resource-container-id="108577"
data-linked-resource-container-version="26"></span></p>
+<p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image"
src="pojo-messaging-example.data/pojo-messaging.jpg"
data-image-src="/confluence/download/attachments/108577/pojo-messaging.jpg?version=1&modificationDate=1233062777000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="9645"
data-linked-resource-version="1" data-linked-resource-type="attachment"
data-linked-resource-default-alias="pojo-messaging.jpg"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/jpeg"
data-linked-resource-container-id="108577"
data-linked-resource-container-version="27"></span></p>
<p>At step 1 the <code>SendFileRecordsToQueueBean</code> polls the
<code>./src/data</code> directory for new files. There are 3 files in this
directory so 3 messages will be created. As shown below, the <a shape="rect"
href="pojo-consuming.html"><code>@Consume</code></a> annotation will cause any
new messages coming from the <code>file:src/data endpoint</code> to be sent to
the <code>onFileSendToQueue</code> method.</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[
-public class SendFileRecordsToQueueBean {
-
- private static final Logger LOG =
LoggerFactory.getLogger(SendFileRecordsToQueueBean.class);
-
- @Produce(uri = "activemq:personnel.records")
- ProducerTemplate producer;
-
- @Consume(uri = "file:src/data?noop=true")
- public void onFileSendToQueue(String body,
@Header("CamelFileName") String name) {
- LOG.info("Incoming file: {}", name);
- producer.sendBody(body);
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=ex|lang=java|url=camel/trunk/examples/camel-example-pojo-messaging/src/main/java/org/apache/camel/example/pojo_messaging/SendFileRecordsToQueueBean.java}</plain-text-body>
<p>At step 2 the <code>SendFileRecordsToQueueBean</code> then sends the
contents of the <code>File</code> message as a <code>String</code> to the
<code>personnel.records</code> JMS queue, which is backed by an embedded
instance of Apache ActiveMQ. The conversion from String to JMS message is
automatic. The <a shape="rect"
href="pojo-producing.html"><code>@Produce</code></a> annotation is used to
access the <a shape="rect" href="activemq.html">ActiveMQ</a> endpoint.</p>
<p>At step 3 the <code>DistributeRecordsBean</code> (shown below) consumes the
JMS message from the <code>personnel.records</code> queue. Again the <a
shape="rect" href="pojo-consuming.html"><code>@Consume</code></a> annotation is
used to get messages from the ActiveMQ endpoint.</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[
-public class DistributeRecordsBean {
-
- private static final Logger LOG =
LoggerFactory.getLogger(DistributeRecordsBean.class);
-
- @Consume(uri = "activemq:personnel.records")
- @RecipientList
- public String[] route(@XPath("/person/city/text()") String city)
{
- if (city.equals("London")) {
- LOG.info("Person is from EMEA region");
- return new String[]
{"file:target/messages/emea/hr_pickup",
-
"file:target/messages/emea/finance_pickup"};
- } else {
- LOG.info("Person is from AMER region");
- return new String[]
{"file:target/messages/amer/hr_pickup",
-
"file:target/messages/amer/finance_pickup"};
- }
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=ex|lang=java|url=camel/trunk/examples/camel-example-pojo-messaging/src/main/java/org/apache/camel/example/pojo_messaging/DistributeRecordsBean.java}</plain-text-body>
<p>You will notice an additional <a shape="rect"
href="recipientlist-annotation.html"><code>@RecipientList</code></a> annotation
on the route method. This turns the method into a <a shape="rect"
href="recipient-list.html">Recipient List</a> EIP where the return value is a
list of URIs for the recipients (can be String[], List<String>, URI[],
etc). This annotation is great for creating custom dynamic Recipient Lists. In
this case at step 4 we peek at the city field in the message (using the <a
shape="rect" href="parameter-binding-annotations.html"><code>@XPath</code></a>
annotation) and provide a set of recipients based on that. For folk from
London, their files will be sent to file locations for the EMEA region
(<code>file:target/messages/emea/...</code>). Others fall into the AMER region
(<code>file:target/messages/amer/...</code>). </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">
+<rich-text-body>
<p>If you have messages that are not XML, don't fret! Camel has ways to get
information out of arbitrary message payloads. For instance, you can try using
the @Bean annotation to peek at the message using your own Java bean.</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[
- @Consume(uri = "activemq:personnel.records")
+<plain-text-body>
+ @Consume(uri = "activemq:personnel.records")
@RecipientList
- public String[] route(@Bean("cityExtractorBean") String city) {
- if (city.equals("London")) {
+ public String[] route(@Bean("cityExtractorBean") String city) {
+ if (city.equals("London")) {
-]]></script>
-</div></div>
+</plain-text-body>
-<p>Check out <a shape="rect"
href="parameter-binding-annotations.html">Parameter Binding Annotations</a> for
more information on this.</p></div></div>
+<p>Check out <a shape="rect"
href="parameter-binding-annotations.html">Parameter Binding Annotations</a> for
more information on this.</p></rich-text-body>
<p>After running the example, browse to the <code>target/messages</code>
directory to see where the messages were saved. </p>