Modified: websites/production/camel/content/load-balancer.html
==============================================================================
--- websites/production/camel/content/load-balancer.html (original)
+++ websites/production/camel/content/load-balancer.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: Load Balancer
@@ -86,218 +75,107 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3 id="LoadBalancer-LoadBalancer">Load
Balancer</h3><p>The Load Balancer Pattern allows you to delegate to one of a
number of endpoints using a variety of different load balancing
policies.</p><h3 id="LoadBalancer-Built-inloadbalancingpolicies">Built-in load
balancing policies</h3><p>Camel provides the following policies
out-of-the-box:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Policy</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.html">Round
Robin</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The
exchanges are selected from in a round robin fashion. This is a well known and
classic policy, which
spreads the load evenly.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.html">Random</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A random endpoint is selected
for each exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.html">Sticky</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Sticky load balancing using an
Expression to calculate a correlation key to perform the sticky load balancing;
rather like jsessionid in the web or JMSXGroupID in JMS.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect"
class="external-link" href="http://camel.apache.org/maven
/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/TopicLoadBalancer.html">Topic</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Topic which sends to all
destinations (rather like JMS Topics)</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.html">Failover</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>In case of failures the
exchange will be tried on the next endpoint.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>Weighted Round-Robin</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> The
weighted load balancing policy allows you to specify a processing load
distribution ratio for each server with respect to the others. In addition to
the weight, endpoint selection is then further refined using <
strong>round-robin</strong> distribution based on weight.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>Weighted Random</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> The
weighted load balancing policy allows you to specify a processing load
distribution ratio for each server with respect to others.In addition to the
weight, endpoint selection is then further refined using
<strong>random</strong> distribution based on weight.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>Custom</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> From Camel 2.8
onwards the preferred way of using a custom <a shape="rect"
href="load-balancer.html">Load Balancer</a> is to use this policy, instead of
using the @deprecated <code>ref</code> attribute.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd">Circuit Breaker</td><td
colspan="1" rowspan="1" class="confluenceTd"><
p><strong>Camel 2.14:</strong> Implements the Circuit Breaker pattern as
described in "Release it!" book.</p></td></tr></tbody></table></div><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Load balancing HTTP endpoints</p><span class="aui-icon
aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>If you are proxying and load
balancing HTTP, then see <a shape="rect"
href="how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html">this
page</a> for more details.</p></div></div><h3
id="LoadBalancer-RoundRobin">Round Robin</h3><p>The round robin load balancer
is not meant to work with failover, for that you should use the dedicated
<strong>failover</strong> load balancer. The round robin load balancer will
only change to next endpoint per message.</p><p>The round robin load balancer
is stateful as it keeps state of which endpoint to use next time.</p><p><str
ong>Using the <a shape="rect" href="fluent-builders.html">Fluent
Builders</a></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[
-from("direct:start").loadBalance().
-roundRobin().to("mock:x", "mock:y", "mock:z");
-]]></script>
-</div></div><strong>Using the Spring configuration</strong><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[<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
+<div class="wiki-content maincontent"><h3 id="LoadBalancer-LoadBalancer">Load
Balancer</h3><p>The Load Balancer Pattern allows you to delegate to one of a
number of endpoints using a variety of different load balancing
policies.</p><h3 id="LoadBalancer-Built-inloadbalancingpolicies">Built-in load
balancing policies</h3><p>Camel provides the following policies
out-of-the-box:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Policy</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.html">Round
Robin</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The
exchanges are selected from in a round robin fashion. This is a well known and
classic policy, which
spreads the load evenly.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.html">Random</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A random endpoint is selected
for each exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.html">Sticky</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Sticky load balancing using an
Expression to calculate a correlation key to perform the sticky load balancing;
rather like jsessionid in the web or JMSXGroupID in JMS.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect"
class="external-link" href="http://camel.apache.org/maven
/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/TopicLoadBalancer.html">Topic</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Topic which sends to all
destinations (rather like JMS Topics)</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.html">Failover</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>In case of failures the
exchange will be tried on the next endpoint.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>Weighted Round-Robin</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> The
weighted load balancing policy allows you to specify a processing load
distribution ratio for each server with respect to the others. In addition to
the weight, endpoint selection is then further refined using <
strong>round-robin</strong> distribution based on weight.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>Weighted Random</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> The
weighted load balancing policy allows you to specify a processing load
distribution ratio for each server with respect to others.In addition to the
weight, endpoint selection is then further refined using
<strong>random</strong> distribution based on weight.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>Custom</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> From Camel 2.8
onwards the preferred way of using a custom <a shape="rect"
href="load-balancer.html">Load Balancer</a> is to use this policy, instead of
using the @deprecated <code>ref</code> attribute.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd">Circuit Breaker</td><td
colspan="1" rowspan="1" class="confluenceTd"><
p><strong>Camel 2.14:</strong> Implements the Circuit Breaker pattern as
described in "Release it!" book.</p></td></tr></tbody></table></div><parameter
ac:name="title">Load balancing HTTP endpoints</parameter><rich-text-body><p>If
you are proxying and load balancing HTTP, then see <a shape="rect"
href="how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html">this
page</a> for more details.</p></rich-text-body><h3
id="LoadBalancer-RoundRobin">Round Robin</h3><p>The round robin load balancer
is not meant to work with failover, for that you should use the dedicated
<strong>failover</strong> load balancer. The round robin load balancer will
only change to next endpoint per message.</p><p>The round robin load balancer
is stateful as it keeps state of which endpoint to use next
time.</p><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent
Builders</a></strong><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apach
e/camel/processor/RoundRobinLoadBalanceTest.java}</plain-text-body><strong>Using
the Spring configuration</strong></p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
<route>
- <from uri="direct:start"/>
+ <from uri="direct:start"/>
<loadBalance>
<roundRobin/>
- <to uri="mock:x"/>
- <to uri="mock:y"/>
- <to uri="mock:z"/>
+ <to uri="mock:x"/>
+ <to uri="mock:y"/>
+ <to uri="mock:z"/>
</loadBalance>
</route>
</camelContext>
-]]></script>
-</div></div><p>The above example loads balance requests from
<strong>direct:start</strong> to one of the available <strong>mock
endpoint</strong> instances, in this case using a round robin policy.<br
clear="none"> For further examples of this pattern look at <a shape="rect"
class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoundRobinLoadBalanceTest.java?view=markup">this
junit test case</a></p><h3 id="LoadBalancer-Failover">Failover</h3><p>The
<code>failover</code> load balancer is capable of trying the next processor in
case an <a shape="rect" href="exchange.html">Exchange</a> failed with an
<code>exception</code> during processing.<br clear="none"> You can constrain
the <code>failover</code> to activate only when one exception of a list you
specify occurs. If you do not specify a list any exception will cause fail over
to occur. This balancer uses the same strategy for matching exceptions as the
<a shape="rect
" href="exception-clause.html">Exception Clause</a> does for the
<strong>onException</strong>.</p><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Enable stream
caching if using streams</p><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>If you use streaming then you
should enable <a shape="rect" href="stream-caching.html">Stream caching</a>
when using the failover load balancer. This is needed so the stream can be
re-read after failing over to the next processor.</p></div></div><p>Failover
offers the following options:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>D
escription</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>inheritErrorHandler</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.3:</strong> Whether or not the <a
shape="rect" href="error-handler.html">Error Handler</a> configured on the
route should be used. Disable this if you want failover to transfer immediately
to the next endpoint. On the other hand, if you have this option enabled, then
Camel will first let the <a shape="rect" href="error-handler.html">Error
Handler</a> try to process the message. The <a shape="rect"
href="error-handler.html">Error Handler</a> may have been configured to
redeliver and use delays between attempts. If you have enabled a number of
redeliveries then Camel will try to redeliver to the <strong>same</strong>
endpoint, and only fail over to the next endpoint, when the <a sh
ape="rect" href="error-handler.html">Error Handler</a> is
exhausted.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>maximumFailoverAttempts</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>-1</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.3:</strong> A value to indicate after X
failover attempts we should exhaust (give up). Use -1 to indicate never give up
and continuously try to failover. Use 0 to never failover. And use e.g. 3 to
failover at most 3 times before giving up. This option can be used whether or
not roundRobin is enabled or not.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>roundRobin</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.3:</strong> Whether or not the <c
ode>failover</code> load balancer should operate in round robin mode or not.
If not, then it will <strong>always</strong> start from the first endpoint when
a new message is to be processed. In other words it restart from the top for
every message. If round robin is enabled, then it keeps state and will continue
with the next endpoint in a round robin fashion. When using round robin it will
not <em>stick</em> to last known good endpoint, it will always pick the next
endpoint to use. <span>You can also enable sticky mode together with round
robin, if so then it will pick the last known good endpoint </span><span>to use
when starting the load balancing (instead of using the next when
starting).</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">sticky</td><td colspan="1" rowspan="1"
class="confluenceTd">boolean</td><td colspan="1" rowspan="1"
class="confluenceTd">false</td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong> Whether or no
t the failover load balancer should operate in sticky mode or not. If not,
then it will always start from the first endpoint when a new message is to be
processed. In other words it restart from the top for every message. If sticky
is enabled, then it keeps state and will continue with the last known good
endpoint. You can also enable sticky mode together with round robin, if so then
it will pick the last known good endpoint to use when starting the load
balancing (instead of using the next when
starting).</td></tr></tbody></table></div><p><strong>Camel 2.2 or older
behavior</strong><br clear="none"> The current implementation of failover load
balancer uses simple logic which <strong>always</strong> tries the first
endpoint, and in case of an exception being thrown it tries the next in the
list, and so forth. It has no state, and the next message will thus
<strong>always</strong> start with the first endpoint.</p><p><strong>Camel 2.3
onwards behavior</strong><br clear="none"> The <c
ode>failover</code> load balancer now supports round robin mode, which allows
you to failover in a round robin fashion. See the <code>roundRobin</code>
option.</p><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Redelivery must be
enabled</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>In Camel 2.2 or older the failover
load balancer requires you have enabled Camel <a shape="rect"
href="error-handler.html">Error Handler</a> to use redelivery. In Camel 2.3
onwards this is not required as such, as you can mix and match. See the
<code>inheritErrorHandler</code> option.</p></div></div><p>Here is a sample to
failover only if a <code>IOException</code> related exception was
thrown:</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")
- // here we will load balance if IOException was thrown
- // any other kind of exception will result in the Exchange as failed
- // to failover over any kind of exception we can just omit the exception
- // in the failOver DSL
- .loadBalance().failover(IOException.class)
- .to("direct:x", "direct:y", "direct:z");
-]]></script>
-</div></div>You can specify multiple exceptions to failover as the option is
varargs, for instance:<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[// enable redelivery so failover can react
+</plain-text-body><p>The above example loads balance requests from
<strong>direct:start</strong> to one of the available <strong>mock
endpoint</strong> instances, in this case using a round robin policy.<br
clear="none"> For further examples of this pattern look at <a shape="rect"
class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoundRobinLoadBalanceTest.java?view=markup">this
junit test case</a></p><h3 id="LoadBalancer-Failover">Failover</h3><p>The
<code>failover</code> load balancer is capable of trying the next processor in
case an <a shape="rect" href="exchange.html">Exchange</a> failed with an
<code>exception</code> during processing.<br clear="none"> You can constrain
the <code>failover</code> to activate only when one exception of a list you
specify occurs. If you do not specify a list any exception will cause fail over
to occur. This balancer uses the same strategy for matching exceptions as the
<a shape
="rect" href="exception-clause.html">Exception Clause</a> does for the
<strong>onException</strong>.</p><parameter ac:name="title">Enable stream
caching if using streams</parameter><rich-text-body><p>If you use streaming
then you should enable <a shape="rect" href="stream-caching.html">Stream
caching</a> when using the failover load balancer. This is needed so the stream
can be re-read after failing over to the next
processor.</p></rich-text-body><p>Failover offers the following
options:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>inheritErrorHandler</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td co
lspan="1" rowspan="1" class="confluenceTd"><p>true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong> Whether or not
the <a shape="rect" href="error-handler.html">Error Handler</a> configured on
the route should be used. Disable this if you want failover to transfer
immediately to the next endpoint. On the other hand, if you have this option
enabled, then Camel will first let the <a shape="rect"
href="error-handler.html">Error Handler</a> try to process the message. The <a
shape="rect" href="error-handler.html">Error Handler</a> may have been
configured to redeliver and use delays between attempts. If you have enabled a
number of redeliveries then Camel will try to redeliver to the
<strong>same</strong> endpoint, and only fail over to the next endpoint, when
the <a shape="rect" href="error-handler.html">Error Handler</a> is
exhausted.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>maximumFailoverAttempts</p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>-1</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.3:</strong> A value to indicate after X
failover attempts we should exhaust (give up). Use -1 to indicate never give up
and continuously try to failover. Use 0 to never failover. And use e.g. 3 to
failover at most 3 times before giving up. This option can be used whether or
not roundRobin is enabled or not.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>roundRobin</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.3:</strong> Whether or not the
<code>failover</code> load balancer should operate in round robin mode or not.
If not, then it will <strong>always</strong> start from the first endpoint when
a new message is to be pr
ocessed. In other words it restart from the top for every message. If round
robin is enabled, then it keeps state and will continue with the next endpoint
in a round robin fashion. When using round robin it will not <em>stick</em> to
last known good endpoint, it will always pick the next endpoint to use.
<span>You can also enable sticky mode together with round robin, if so then it
will pick the last known good endpoint </span><span>to use when starting the
load balancing (instead of using the next when
starting).</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">sticky</td><td colspan="1" rowspan="1"
class="confluenceTd">boolean</td><td colspan="1" rowspan="1"
class="confluenceTd">false</td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16:</strong> Whether or not the failover
load balancer should operate in sticky mode or not. If not, then it will always
start from the first endpoint when a new message is to be processed. In other
words it
restart from the top for every message. If sticky is enabled, then it keeps
state and will continue with the last known good endpoint. You can also enable
sticky mode together with round robin, if so then it will pick the last known
good endpoint to use when starting the load balancing (instead of using the
next when starting).</td></tr></tbody></table></div><p><strong>Camel 2.2 or
older behavior</strong><br clear="none"> The current implementation of failover
load balancer uses simple logic which <strong>always</strong> tries the first
endpoint, and in case of an exception being thrown it tries the next in the
list, and so forth. It has no state, and the next message will thus
<strong>always</strong> start with the first endpoint.</p><p><strong>Camel 2.3
onwards behavior</strong><br clear="none"> The <code>failover</code> load
balancer now supports round robin mode, which allows you to failover in a round
robin fashion. See the <code>roundRobin</code> option.</p><parameter ac:name=
"title">Redelivery must be enabled</parameter><rich-text-body><p>In Camel 2.2
or older the failover load balancer requires you have enabled Camel <a
shape="rect" href="error-handler.html">Error Handler</a> to use redelivery. In
Camel 2.3 onwards this is not required as such, as you can mix and match. See
the <code>inheritErrorHandler</code> option.</p></rich-text-body><p>Here is a
sample to failover only if a <code>IOException</code> related exception was
thrown:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverNotCatchedExceptionTest.java}</plain-text-body>You
can specify multiple exceptions to failover as the option is varargs, for
instance:</p><parameter ac:name="">java</parameter><plain-text-body>// enable
redelivery so failover can react
errorHandler(defaultErrorHandler().maximumRedeliveries(5));
-from("direct:foo").
+from("direct:foo").
loadBalance().failover(IOException.class, MyOtherException.class)
- .to("direct:a", "direct:b");
-]]></script>
-</div></div><h4 id="LoadBalancer-UsingfailoverinSpringDSL">Using failover in
Spring DSL</h4><p>Failover can also be used from Spring DSL and you configure
it as:</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
errorHandlerRef="myErrorHandler">
- <from uri="direct:foo"/>
+ .to("direct:a", "direct:b");
+</plain-text-body><h4 id="LoadBalancer-UsingfailoverinSpringDSL">Using
failover in Spring DSL</h4><p>Failover can also be used from Spring DSL and you
configure it as:</p><parameter ac:name="">xml</parameter><plain-text-body>
<route errorHandlerRef="myErrorHandler">
+ <from uri="direct:foo"/>
<loadBalance>
<failover>
<exception>java.io.IOException</exception>
<exception>com.mycompany.MyOtherException</exception>
</failover>
- <to uri="direct:a"/>
- <to uri="direct:b"/>
+ <to uri="direct:a"/>
+ <to uri="direct:b"/>
</loadBalance>
</route>
-]]></script>
-</div></div><h4 id="LoadBalancer-Usingfailoverinroundrobinmode">Using failover
in round robin mode</h4><p>An example using 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[
-from("direct:start")
- // Use failover load balancer in stateful round robin mode
- // which mean it will failover immediately in case of an exception
- // as it does NOT inherit error handler. It will also keep retrying as
- // its configured to newer exhaust.
- .loadBalance().failover(-1, false, true).
- to("direct:bad", "direct:bad2",
"direct:good", "direct:good2");
-]]></script>
-</div></div>And the same example using Spring XML:<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"/>
- <loadBalance>
- <!-- failover using stateful round robin,
- which will keep retrying forever those 4 endpoints until success.
- You can set the maximumFailoverAttempt to break out after X
attempts -->
- <failover roundRobin="true"/>
- <to uri="direct:bad"/>
- <to uri="direct:bad2"/>
- <to uri="direct:good"/>
- <to uri="direct:good2"/>
- </loadBalance>
-</route>
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Disabled
inheritErrorHandler</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 configure
<code>inheritErrorHandler=false</code> if you want to failover to the next
endpoint as fast as possible. By disabling the <a shape="rect"
href="error-handler.html">Error Handler</a> you ensure it does not
<em>intervene</em> which allows the <code>failover</code> load balancer to
handle failover asap. By also enabling <code>roundRobin</code> mode, then it
will keep retrying until it success. You can then configure the
<code>maximumFailoverAttempts</code> option to a high value to let it
eventually exhaust (give up) and fail.</p></div></div><h3
id="LoadBalancer-WeightedRound-RobinandRandomLoadBalancing">Weighted
Round-Robin and Random Load Balancing</h3><p><strong>Available as of Camel
2.5</strong></p><p>In many enterprise environments where server nodes of
unequal processing power & performance characteristics are utilized to host
services and processing endpoints, it is frequently necessary to distribute
processing load based on their individual server capabilities so that some
endpoints are not unfairly burdened with requests. Obviously simple round-robin
or random load balancing do not alleviate problems of this nature. A Weighted
Round-Robin and/or Weighted Random load balancer can be used to address this
problem.</p><p>The weighted load balancing policy allows you to specify a
processing load distribution ratio for each server with respect to others. You
can specify this as a positive processing weight for each server. A larger
number indicates that the server can handle a larger load. The weight is
utilized to determine the payload distribution ratio to different processing
endpoints with respect to others.</p><div class="confluence-information-macro co
nfluence-information-macro-tip"><p class="title">Disabled
inheritErrorHandler</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>As of Camel 2.6, the Weighted Load
balancer usage has been further simplified, there is no need to send in
distributionRatio as a List<Integer>. It can be simply sent as a
delimited String of integer weights separated by a delimiter of
choice.</p></div></div><p>The parameters that can be used are</p><p><strong>In
Camel 2.5</strong></p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>roundRobin</p></td><td c
olspan="1" rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The default value for round-robin is false. In the
absence of this setting or parameter the load balancing algorithm used is
random.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>distributionRatio</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>List<Integer></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The distributionRatio is a list consisting on integer
weights passed in as a parameter. The distributionRatio must match the number
of endpoints and/or processors specified in the load balancer list. In Camel
2.5 if endpoints do not match ratios, then a best effort distribution is
attempted.</p></td></tr></tbody></table></div><p><strong>Available In Camel
2.6</strong></p><div class="table
-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>roundRobin</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The default value for round-robin is false. In the
absence of this setting or parameter the load balancing algorithm used is
random.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>distributionRatio</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><
p>The distributionRatio is a delimited String consisting on integer weights
separated by delimiters for example "2,3,5". The distributionRatio must match
the number of endpoints and/or processors specified in the load balancer
list.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>distributionRatioDelimiter</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>,</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The distributionRatioDelimiter is the delimiter used to
specify the distributionRatio. If this attribute is not specified a default
delimiter "," is expected as the delimiter used for specifying the
distributionRatio.</p></td></tr></tbody></table></div><h4
id="LoadBalancer-UsingWeightedround-robin&randomloadbalancing">Using
Weighted round-robin & random load balancing</h4><p><strong>In Camel
2.5</strong></p><p>An example using 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[ArrayList<integer> distributionRatio =
new ArrayList<integer>();
+</plain-text-body><h4 id="LoadBalancer-Usingfailoverinroundrobinmode">Using
failover in round robin mode</h4><p>An example using Java
DSL:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailoverRoundRobinTest.java}</plain-text-body>And
the same example using Spring
XML:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailoverRoundRobinTest.xml}</plain-text-body></p><parameter
ac:name="title">Disabled inheritErrorHandler</parameter><rich-text-body><p>You
can configure <code>inheritErrorHandler=false</code> if you want to failover to
the next endpoint as fast as possible. By disabling the <a shape="rect"
href="error-handler.html">Error Handler</a> you ensure it does not
<em>intervene</em> which allows the <code>failover</code> load balancer to
handle failover asap. By also enabling <code>roundRobin</code> mode, then it
will keep retrying un
til it success. You can then configure the
<code>maximumFailoverAttempts</code> option to a high value to let it
eventually exhaust (give up) and fail.</p></rich-text-body><h3
id="LoadBalancer-WeightedRound-RobinandRandomLoadBalancing">Weighted
Round-Robin and Random Load Balancing</h3><p><strong>Available as of Camel
2.5</strong></p><p>In many enterprise environments where server nodes of
unequal processing power & performance characteristics are utilized to host
services and processing endpoints, it is frequently necessary to distribute
processing load based on their individual server capabilities so that some
endpoints are not unfairly burdened with requests. Obviously simple round-robin
or random load balancing do not alleviate problems of this nature. A Weighted
Round-Robin and/or Weighted Random load balancer can be used to address this
problem.</p><p>The weighted load balancing policy allows you to specify a
processing load distribution ratio for each server with respect
to others. You can specify this as a positive processing weight for each
server. A larger number indicates that the server can handle a larger load. The
weight is utilized to determine the payload distribution ratio to different
processing endpoints with respect to others.</p><parameter
ac:name="title">Disabled inheritErrorHandler</parameter><rich-text-body><p>As
of Camel 2.6, the Weighted Load balancer usage has been further simplified,
there is no need to send in distributionRatio as a List<Integer>. It can
be simply sent as a delimited String of integer weights separated by a
delimiter of choice.</p></rich-text-body><p>The parameters that can be used
are</p><p><strong>In Camel 2.5</strong></p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rows
pan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>roundRobin</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The default value for round-robin is false. In the
absence of this setting or parameter the load balancing algorithm used is
random.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>distributionRatio</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>List<Integer></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The distributionRatio is a list consisting on integer
weights passed in as a parameter. The distributionRatio must match the number
of endpoints and/or processors specified in the load balancer list. In Camel
2.5 if endpoints do not match ratios, then a
best effort distribution is
attempted.</p></td></tr></tbody></table></div><p><strong>Available In Camel
2.6</strong></p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>roundRobin</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The default value for round-robin is false. In the
absence of this setting or parameter the load balancing algorithm used is
random.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>distributionRatio</p></td><td colspan="1" rowspan="1"
class="confluence
Td"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The distributionRatio is a delimited String consisting
on integer weights separated by delimiters for example "2,3,5". The
distributionRatio must match the number of endpoints and/or processors
specified in the load balancer list.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>distributionRatioDelimiter</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>,</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The distributionRatioDelimiter is the delimiter used to
specify the distributionRatio. If this attribute is not specified a default
delimiter "," is expected as the delimiter used for specifying the
distributionRatio.</p></td></tr></tbody></table></div><h4
id="LoadBalancer-UsingWeightedround-robin&randomloadbalancing">Using
Weighted rou
nd-robin & random load balancing</h4><p><strong>In Camel
2.5</strong></p><p>An example using Java DSL:</p><parameter
ac:name="">java</parameter><plain-text-body>ArrayList<integer>
distributionRatio = new ArrayList<integer>();
distributionRatio.add(4);
distributionRatio.add(2);
distributionRatio.add(1);
// round-robin
-from("direct:start")
+from("direct:start")
.loadBalance().weighted(true, distributionRatio)
- .to("mock:x", "mock:y", "mock:z");
+ .to("mock:x", "mock:y", "mock:z");
//random
-from("direct:start")
+from("direct:start")
.loadBalance().weighted(false, distributionRatio)
- .to("mock:x", "mock:y", "mock:z");
-]]></script>
-</div></div><p>And the same example using Spring XML:</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"/>
+ .to("mock:x", "mock:y", "mock:z");
+</plain-text-body><p>And the same example using Spring XML:</p><parameter
ac:name="">xml</parameter><plain-text-body> <route>
+ <from uri="direct:start"/>
<loadBalance>
- <weighted roundRobin="false" distributionRatio="4 2
1"/>
- <to uri="mock:x"/>
- <to uri="mock:y"/>
- <to uri="mock:z"/>
+ <weighted roundRobin="false" distributionRatio="4 2 1"/>
+ <to uri="mock:x"/>
+ <to uri="mock:y"/>
+ <to uri="mock:z"/>
</loadBalance>
</route>
-]]></script>
-</div></div><p><strong>Available In Camel 2.6</strong></p><p>An example using
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[// round-robin
-from("direct:start")
- .loadBalance().weighted(true, "4:2:1"
distributionRatioDelimiter=":")
- .to("mock:x", "mock:y", "mock:z");
+</plain-text-body><p><strong>Available In Camel 2.6</strong></p><p>An example
using Java DSL:</p><parameter ac:name="">java</parameter><plain-text-body>//
round-robin
+from("direct:start")
+ .loadBalance().weighted(true, "4:2:1" distributionRatioDelimiter=":")
+ .to("mock:x", "mock:y", "mock:z");
//random
-from("direct:start")
- .loadBalance().weighted(false, "4,2,1")
- .to("mock:x", "mock:y", "mock:z");
-]]></script>
-</div></div><p>And the same example using Spring XML:</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"/>
+from("direct:start")
+ .loadBalance().weighted(false, "4,2,1")
+ .to("mock:x", "mock:y", "mock:z");
+</plain-text-body><p>And the same example using Spring XML:</p><parameter
ac:name="">xml</parameter><plain-text-body> <route>
+ <from uri="direct:start"/>
<loadBalance>
- <weighted roundRobin="false"
distributionRatio="4-2-1" distributionRatioDelimiter="-"
/>
- <to uri="mock:x"/>
- <to uri="mock:y"/>
- <to uri="mock:z"/>
+ <weighted roundRobin="false" distributionRatio="4-2-1"
distributionRatioDelimiter="-" />
+ <to uri="mock:x"/>
+ <to uri="mock:y"/>
+ <to uri="mock:z"/>
</loadBalance>
</route>
-]]></script>
-</div></div><h3 id="LoadBalancer-CustomLoadBalancer">Custom Load
Balancer</h3><p>You can use a custom load balancer (eg your own implementation)
also.</p><p>An example using 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[
-from("direct:start")
- // using our custom load balancer
- .loadBalance(new MyLoadBalancer())
- .to("mock:x", "mock:y", "mock:z");
-]]></script>
-</div></div>And the same example using XML DSL:<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 the implementation of our custom load balancer -->
-<bean id="myBalancer"
class="org.apache.camel.processor.CustomLoadBalanceTest$MyLoadBalancer"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <loadBalance>
- <!-- refer to my custom load balancer -->
- <custom ref="myBalancer"/>
- <!-- these are the endpoints to balancer -->
- <to uri="mock:x"/>
- <to uri="mock:y"/>
- <to uri="mock:z"/>
- </loadBalance>
- </route>
-</camelContext>
-]]></script>
-</div></div>Notice in the XML DSL above we use <custom> which is only
available in <strong>Camel 2.8</strong> onwards. In older releases you would
have to do as follows instead:<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[ <loadBalance
ref="myBalancer">
+</plain-text-body><h3 id="LoadBalancer-CustomLoadBalancer">Custom Load
Balancer</h3><p>You can use a custom load balancer (eg your own implementation)
also.</p><p>An example using Java
DSL:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CustomLoadBalanceTest.java}</plain-text-body>And
the same example using XML
DSL:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomRefLoadBalanceTest.xml}</plain-text-body>Notice
in the XML DSL above we use <custom> which is only available in
<strong>Camel 2.8</strong> onwards. In older releases you would have to do as
follows instead:</p><parameter ac:name="">xml</parameter><plain-text-body>
<loadBalance ref="myBalancer">
<!-- these are the endpoints to balancer -->
- <to uri="mock:x"/>
- <to uri="mock:y"/>
- <to uri="mock:z"/>
+ <to uri="mock:x"/>
+ <to uri="mock:y"/>
+ <to uri="mock:z"/>
</loadBalance>
-]]></script>
-</div></div><p>To implement a custom load balancer you can extend some support
classes such as <code>LoadBalancerSupport</code> and
<code>SimpleLoadBalancerSupport</code>. The former supports the asynchronous
routing engine, and the latter does not. Here is an example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Custom load balancer
implementation</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public static class MyLoadBalancer extends LoadBalancerSupport {
-
- public boolean process(Exchange exchange, AsyncCallback callback) {
- String body = exchange.getIn().getBody(String.class);
- try {
- if ("x".equals(body)) {
- getProcessors().get(0).process(exchange);
- } else if ("y".equals(body)) {
- getProcessors().get(1).process(exchange);
- } else {
- getProcessors().get(2).process(exchange);
- }
- } catch (Throwable e) {
- exchange.setException(e);
- }
- callback.done(true);
- return true;
- }
-}
-]]></script>
-</div></div><h3 id="LoadBalancer-CircuitBreaker">Circuit Breaker</h3><p>The
Circuit Breaker load balancer is a stateful pattern that monitors all calls for
certain exceptions. Initially the Circuit Breaker is in closed state and passes
all messages. If there are failures and the threshold is reached, it moves to
open state and rejects all calls until halfOpenAfter timeout is reached. After
this timeout is reached, if there is a new call, it will pass and if the result
is success the Circuit Breaker will move to closed state, or to open state if
there was an error.</p><p>When the circuit breaker is closed, it will throw a
<code>java.util.concurrent.RejectedExecutionException</code>. This can then be
caught to provide an alternate path for processing exchanges.</p><p>An example
using 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[from("direct:start")
+</plain-text-body><p>To implement a custom load balancer you can extend some
support classes such as <code>LoadBalancerSupport</code> and
<code>SimpleLoadBalancerSupport</code>. The former supports the asynchronous
routing engine, and the latter does not. Here is an
example:<plain-text-body>{snippet:id=e2|title=Custom load balancer
implementation|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CustomLoadBalanceTest.java}</plain-text-body></p><h3
id="LoadBalancer-CircuitBreaker">Circuit Breaker</h3><p>The Circuit Breaker
load balancer is a stateful pattern that monitors all calls for certain
exceptions. Initially the Circuit Breaker is in closed state and passes all
messages. If there are failures and the threshold is reached, it moves to open
state and rejects all calls until halfOpenAfter timeout is reached. After this
timeout is reached, if there is a new call, it will pass and if the result is
success the Circuit Breaker will move to closed state, or
to open state if there was an error.</p><p>When the circuit breaker is
closed, it will throw a
<code>java.util.concurrent.RejectedExecutionException</code>. This can then be
caught to provide an alternate path for processing exchanges.</p><p>An example
using Java DSL:</p><parameter
ac:name="">java</parameter><plain-text-body>from("direct:start")
.onException(RejectedExecutionException.class)
.handled(true)
- .to("mock:serviceUnavailable")
+ .to("mock:serviceUnavailable")
.end()
- Â .loadBalance()
+  .loadBalance()
.circuitBreaker(2, 1000L, MyCustomException.class)
- .to("mock:service")
+ .to("mock:service")
.end();
-]]></script>
-</div></div><p>And the same example using Spring XML:</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[<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
+</plain-text-body><p>And the same example using Spring XML:</p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
<route>
- <from uri="direct:start"/>
+ <from uri="direct:start"/>
<onException>
<exception>java.util.concurrent.RejectedExecutionException</exception>
<handled><constant>true</constant></handled>
- <to uri="mock:serviceUnavailable"/>
+ <to uri="mock:serviceUnavailable"/>
</onException>
- Â <loadBalance>
- <circuitBreaker threshold="2"
halfOpenAfter="1000">
+  <loadBalance>
+ <circuitBreaker threshold="2" halfOpenAfter="1000">
<exception>MyCustomException</exception>
</circuitBreaker>
- <to uri="mock:service"/>
+ <to uri="mock:service"/>
</loadBalance>
</route>
</camelContext>
-]]></script>
-</div></div><p></p><h4 id="LoadBalancer-UsingThisPattern">Using This
Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="using-this-pattern.html">Using This Pattern</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/loop.html
==============================================================================
--- websites/production/camel/content/loop.html (original)
+++ websites/production/camel/content/loop.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: Loop
@@ -86,102 +75,24 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Loop-Loop">Loop</h2><p>The Loop
allows for processing a message a number of times, possibly in a different way
for each iteration. Useful mostly during testing.</p><div
class="confluence-information-macro
confluence-information-macro-information"><p class="title">Default
mode</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Notice by default the loop uses
the same exchange throughout the looping. So the result from the previous
iteration will be used for the next (eg <a shape="rect"
href="pipes-and-filters.html">Pipes and Filters</a>). From <strong>Camel
2.8</strong> onwards you can enable copy mode instead. See the options table
for more details.</p></div></div><h3 id="Loop-Options">Options</h3><div
class="confluenceTableSmall"> </div>
-
-
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Default Value</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>copy</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong>
Whether or not copy mode is used. If <code>false</code> then the same Exchange
will be used for each iteration. So the result from the previous iteration will
be <em>visible</em> for the next iteration. Instead you can enable copy mode,
and then each iteration <em>restarts</em> with a fresh copy of the input <a
shape="rect" href="exchange.html">Exchange</a>.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd">doWhile</td><td colspan="1"
rowspan="1" class="
confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.17:</strong> Enables the while loop that
loops until the predicate evaluates to false or
null.</td></tr></tbody></table></div><h3 id="Loop-Exchangeproperties">Exchange
properties</h3><p>For each iteration two properties are set on the
<code>Exchange</code>. Processors can rely on these properties to process the
<a shape="rect" href="message.html">Message</a> in different ways.</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelLoopSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Total number of loops. This is not
available if running the loop in while loop mode.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>CamelLoop
Index</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Index
of the current iteration (0 based)</p></td></tr></tbody></table></div><h4
id="Loop-Examples">Examples</h4><p>The following example shows how to take a
request from the <strong>direct:x</strong> endpoint, then send the message
repetitively to <strong>mock:result</strong>. The number of times the message
is sent is either passed as an argument to <code>loop()</code>, or determined
at runtime by evaluating an expression. The expression <strong>must</strong>
evaluate to an <code>int</code>, otherwise a <code>RuntimeCamelException</code>
is thrown.</p><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></p><p>Pass loop count
as an argument</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:a").loop(8).to("mock:result");
-]]></script>
-</div></div>Use expression to determine loop count<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:b").loop(header("loop")).to("mock:result");
-]]></script>
-</div></div>Use expression to determine loop count<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:c").loop().xpath("/hello/@times").to("mock:result");
-]]></script>
-</div></div><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML Extensions</a></strong><p>Pass
loop count as an argument</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:a"/>
- <loop>
- <constant>8</constant>
- <to uri="mock:result"/>
- </loop>
-</route>
-]]></script>
-</div></div>Use expression to determine loop count<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:b"/>
- <loop>
- <header>loop</header>
- <to uri="mock:result"/>
- </loop>
-</route>
-]]></script>
-</div></div>For further examples of this pattern in use you could look at one
of the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java?view=markup">junit
test case</a><h4 id="Loop-Usingcopymode">Using copy
mode</h4><p><strong>Available as of Camel 2.8</strong></p><p>Now suppose we
send a message to "direct:start" endpoint containing the letter A.<br
clear="none"> The output of processing this route will be that, each
"mock:loop" endpoint will receive "AB" as message.</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")
- // instruct loop to use copy mode, which mean it will use a copy of the
input exchange
- // for each loop iteration, instead of keep using the same exchange all
over
- .loop(3).copy()
- .transform(body().append("B"))
- .to("mock:loop")
- .end()
- .to("mock:result");
-]]></script>
-</div></div>However if we do <strong>not</strong> enable copy mode then
"mock:loop" will receive "AB", "ABB", "ABBB", etc. messages.<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")
- // by default loop will keep using the same exchange so on the 2nd and 3rd
iteration its
- // the same exchange that was previous used that are being looped all over
- .loop(3)
- .transform(body().append("B"))
- .to("mock:loop")
+<div class="wiki-content maincontent"><h2 id="Loop-Loop">Loop</h2><p>The Loop
allows for processing a message a number of times, possibly in a different way
for each iteration. Useful mostly during testing.</p><parameter
ac:name="title">Default mode</parameter><rich-text-body><p>Notice by default
the loop uses the same exchange throughout the looping. So the result from the
previous iteration will be used for the next (eg <a shape="rect"
href="pipes-and-filters.html">Pipes and Filters</a>). From <strong>Camel
2.8</strong> onwards you can enable copy mode instead. See the options table
for more details.</p></rich-text-body><h3
id="Loop-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body> </rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1" cl
ass="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>copy</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.8:</strong> Whether or not copy mode is
used. If <code>false</code> then the same Exchange will be used for each
iteration. So the result from the previous iteration will be <em>visible</em>
for the next iteration. Instead you can enable copy mode, and then each
iteration <em>restarts</em> with a fresh copy of the input <a shape="rect"
href="exchange.html">Exchange</a>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">doWhile</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.17:</strong> Enables the while loop that
loops until the predicate evaluates to false or
null.</td></tr></tbody></table></div><h3 id="Loop-Exchan
geproperties">Exchange properties</h3><p>For each iteration two properties are
set on the <code>Exchange</code>. Processors can rely on these properties to
process the <a shape="rect" href="message.html">Message</a> in different
ways.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Property</p></th><th
colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>CamelLoopSize</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Total number of loops. This is
not available if running the loop in while loop mode.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelLoopIndex</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Index of the current iteration (0
based)</p></td></tr></tbody></table></div><h4
id="Loop-Examples">Examples</h4><p>The following example shows how to take a
reque
st from the <strong>direct:x</strong> endpoint, then send the message
repetitively to <strong>mock:result</strong>. The number of times the message
is sent is either passed as an argument to <code>loop()</code>, or determined
at runtime by evaluating an expression. The expression <strong>must</strong>
evaluate to an <code>int</code>, otherwise a <code>RuntimeCamelException</code>
is thrown.</p><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></p><p>Pass loop count
as an
argument<plain-text-body>{snippet:id=ex1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java}</plain-text-body>Use
expression to determine loop
count<plain-text-body>{snippet:id=ex2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java}</plain-text-body>Use
expression to determine loop
count<plain-text-body>{snippet:id=ex3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/process
or/LoopTest.java}</plain-text-body><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><p>Pass
loop count as an
argument<plain-text-body>{snippet:id=ex1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml}</plain-text-body>Use
expression to determine loop
count<plain-text-body>{snippet:id=ex2|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml}</plain-text-body>For
further examples of this pattern in use you could look at one of the <a
shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java?view=markup">junit
test case</a></p><h4 id="Loop-Usingcopymode">Using copy
mode</h4><p><strong>Available as of Camel 2.8</strong></p><p>Now suppose we
send a message to "direct:start" endpoint containing the letter A.<br
clear="none"> Th
e output of processing this route will be that, each "mock:loop" endpoint will
receive "AB" as
message.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopCopyTest.java}</plain-text-body>However
if we do <strong>not</strong> enable copy mode then "mock:loop" will receive
"AB", "ABB", "ABBB", etc.
messages.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopNoCopyTest.java}</plain-text-body>The
equivalent example in XML DSL in copy mode is as
follows:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringLoopCopyTest.xml}</plain-text-body></p><h4
id="Loop-Usingwhilemode">Using while mode</h4><p><strong>Available as of Camel
2.17</strong></p><p>The loop can act like a while loop that loops until the
expression evaluates to false or null.</p><p>For example the route below loops
wh
ile the length of the message body is 5 or less characters. Notice that the
DSL
uses <strong>loopDoWhile</strong>.</p><plain-text-body>from("direct:start")
+ .loopDoWhile(simple("${body.length} <= 5"))
+ .to("mock:loop")
+ .transform(body().append("A"))
.end()
- .to("mock:result");
-]]></script>
-</div></div>The equivalent example in XML DSL in copy mode is as follows:<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"/>
- <!-- enable copy mode for loop eip -->
- <loop copy="true">
- <constant>3</constant>
- <transform>
- <simple>${body}B</simple>
- </transform>
- <to uri="mock:loop"/>
- </loop>
- <to uri="mock:result"/>
-</route>
-]]></script>
-</div></div><h4 id="Loop-Usingwhilemode">Using while
mode</h4><p><strong>Available as of Camel 2.17</strong></p><p>The loop can act
like a while loop that loops until the expression evaluates to false or
null.</p><p>For example the route below loops while the length of the message
body is 5 or less characters. Notice that the DSL
uses <strong>loopDoWhile</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[from("direct:start")
- .loopDoWhile(simple("${body.length} <= 5"))
- .to("mock:loop")
- .transform(body().append("A"))
- .end()
- .to("mock:result");]]></script>
-</div></div><p>And the same example in XML:</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"/>
- <loop doWhile="true">
+ .to("mock:result");</plain-text-body><p>And the same example in
XML:</p><parameter ac:name="">xml</parameter><plain-text-body> <route>
+ <from uri="direct:start"/>
+ <loop doWhile="true">
<simple>${body.length} &lt;= 5</simple>
- <to uri="mock:loop"/>
+ <to uri="mock:loop"/>
<transform>
<simple>A${body}</simple>
</transform>
</loop>
- <to uri="mock:result"/>
+ <to uri="mock:result"/>
</route>
-]]></script>
-</div></div><p>Notice in XML that the while loop is turned on using the
<strong>doWhile</strong> attribute.</p><p> </p><p></p><h4
id="Loop-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+</plain-text-body><p>Notice in XML that the while loop is turned on using the
<strong>doWhile</strong> attribute.</p><p> </p><p><parameter ac:name=""><a
shape="rect" href="using-this-pattern.html">Using This
Pattern</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/normalizer.html
==============================================================================
--- websites/production/camel/content/normalizer.html (original)
+++ websites/production/camel/content/normalizer.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: Normalizer
@@ -97,73 +86,24 @@
<p>This example shows a Message Normalizer that converts two types of XML
messages into a common format. Messages in this common format are then
filtered.</p>
<p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent
Builders</a></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[
-// we need to normalize two types of incoming messages
-from("direct:start")
- .choice()
-
.when().xpath("/employee").to("bean:normalizer?method=employeeToPerson")
-
.when().xpath("/customer").to("bean:normalizer?method=customerToPerson")
- .end()
- .to("mock:result");
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java}</plain-text-body>
<p>In this case we're using a Java bean as the normalizer. The class looks
like this</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 MyNormalizer {
- public void employeeToPerson(Exchange exchange,
@XPath("/employee/name/text()") String name) {
- exchange.getOut().setBody(createPerson(name));
- }
-
- public void customerToPerson(Exchange exchange,
@XPath("/customer/@name") String name) {
- exchange.getOut().setBody(createPerson(name));
- }
-
- private String createPerson(String name) {
- return "<person name=\"" + name +
"\"/>";
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java}</plain-text-body>
<p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring
XML Extensions</a></strong></p>
<p>The same example in the 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[
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <choice>
- <when>
- <xpath>/employee</xpath>
- <to uri="bean:normalizer?method=employeeToPerson"/>
- </when>
- <when>
- <xpath>/customer</xpath>
- <to uri="bean:normalizer?method=customerToPerson"/>
- </when>
- </choice>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-
-<bean id="normalizer"
class="org.apache.camel.processor.MyNormalizer"/>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml}</plain-text-body>
<h4 id="Normalizer-SeeAlso">See Also</h4>
<ul><li><a shape="rect" href="message-router.html">Message
Router</a></li><li><a shape="rect" href="content-based-router.html">Content
Based Router</a></li><li><a shape="rect" href="message-translator.html">Message
Translator</a></li></ul>
-<h4 id="Normalizer-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+<parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using
This Pattern</a></parameter></div>
</td>
<td valign="top">
<div class="navigation">