Modified: websites/production/camel/content/load-balancer.html
==============================================================================
--- websites/production/camel/content/load-balancer.html (original)
+++ websites/production/camel/content/load-balancer.html Sun Jul 12 09:19:43 
2015
@@ -91,20 +91,20 @@
 from("direct:start").loadBalance().
 roundRobin().to("mock:x", "mock:y", "mock:z");
 ]]></script>
-</div></div><p><strong>Using the Spring configuration</strong></p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">&lt;camelContext id="camel" 
xmlns="http://camel.apache.org/schema/spring"&gt;
+</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[&lt;camelContext id=&quot;camel&quot; 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
   &lt;route&gt;
-    &lt;from uri="direct:start"/&gt;
+    &lt;from uri=&quot;direct:start&quot;/&gt;
     &lt;loadBalance&gt;        
         &lt;roundRobin/&gt;
-        &lt;to uri="mock:x"/&gt;        
-        &lt;to uri="mock:y"/&gt;       
-        &lt;to uri="mock:z"/&gt;                 
+        &lt;to uri=&quot;mock:x&quot;/&gt;        
+        &lt;to uri=&quot;mock:y&quot;/&gt;       
+        &lt;to uri=&quot;mock:z&quot;/&gt;                 
     &lt;/loadBalance&gt;
   &lt;/route&gt;
 &lt;/camelContext&gt;
-</pre>
-</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.</p></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><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>
+</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(&quot;direct:start&quot;)
     // here we will load balance if IOException was thrown
@@ -114,27 +114,27 @@ from(&quot;direct:start&quot;)
     .loadBalance().failover(IOException.class)
         .to(&quot;direct:x&quot;, &quot;direct:y&quot;, &quot;direct:z&quot;);
 ]]></script>
-</div></div><p>You can specify multiple exceptions to failover as the option 
is varargs, for instance:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" 
style="font-size:12px;">// enable redelivery so failover can react
+</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
 errorHandler(defaultErrorHandler().maximumRedeliveries(5));
 
-from("direct:foo").
+from(&quot;direct:foo&quot;).
     loadBalance().failover(IOException.class, MyOtherException.class)
-        .to("direct:a", "direct:b");
-</pre>
+        .to(&quot;direct:a&quot;, &quot;direct:b&quot;);
+]]></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">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">   &lt;route errorHandlerRef="myErrorHandler"&gt;
-      &lt;from uri="direct:foo"/&gt;
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[   &lt;route 
errorHandlerRef=&quot;myErrorHandler&quot;&gt;
+      &lt;from uri=&quot;direct:foo&quot;/&gt;
       &lt;loadBalance&gt;
           &lt;failover&gt;
               &lt;exception&gt;java.io.IOException&lt;/exception&gt;
               &lt;exception&gt;com.mycompany.MyOtherException&lt;/exception&gt;
           &lt;/failover&gt;
-          &lt;to uri="direct:a"/&gt;
-          &lt;to uri="direct:b"/&gt;
+          &lt;to uri=&quot;direct:a&quot;/&gt;
+          &lt;to uri=&quot;direct:b&quot;/&gt;
       &lt;/loadBalance&gt;
     &lt;/route&gt;
-</pre>
+]]></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(&quot;direct:start&quot;)
@@ -145,7 +145,7 @@ from(&quot;direct:start&quot;)
     .loadBalance().failover(-1, false, true).
         to(&quot;direct:bad&quot;, &quot;direct:bad2&quot;, 
&quot;direct:good&quot;, &quot;direct:good2&quot;);
 ]]></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">
+</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[
 &lt;route&gt;
     &lt;from uri=&quot;direct:start&quot;/&gt;
@@ -162,54 +162,54 @@ from(&quot;direct:start&quot;)
 &lt;/route&gt;
 ]]></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 &amp; 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&lt;Integer&gt;. 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&lt;Integer&gt;</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&amp;randomloadbalancing">Using 
Weighted round-robin &amp; 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">
-<pre class="brush: java; gutter: false; theme: Default" 
style="font-size:12px;">ArrayList&lt;integer&gt; distributionRatio = new 
ArrayList&lt;integer&gt;();
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[ArrayList&lt;integer&gt; distributionRatio = 
new ArrayList&lt;integer&gt;();
 distributionRatio.add(4);
 distributionRatio.add(2);
 distributionRatio.add(1);
 
 // round-robin
-from("direct:start")
+from(&quot;direct:start&quot;)
     .loadBalance().weighted(true, distributionRatio)
-    .to("mock:x", "mock:y", "mock:z");
+    .to(&quot;mock:x&quot;, &quot;mock:y&quot;, &quot;mock:z&quot;);
 
 //random
-from("direct:start")
+from(&quot;direct:start&quot;)
     .loadBalance().weighted(false, distributionRatio)
-    .to("mock:x", "mock:y", "mock:z");
-</pre>
+    .to(&quot;mock:x&quot;, &quot;mock:y&quot;, &quot;mock:z&quot;);
+]]></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">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">    &lt;route&gt;
-      &lt;from uri="direct:start"/&gt;
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[    &lt;route&gt;
+      &lt;from uri=&quot;direct:start&quot;/&gt;
       &lt;loadBalance&gt;
-        &lt;weighted roundRobin="false" distributionRatio="4 2 1"/&gt;
-          &lt;to uri="mock:x"/&gt;
-          &lt;to uri="mock:y"/&gt;
-          &lt;to uri="mock:z"/&gt;
+        &lt;weighted roundRobin=&quot;false&quot; distributionRatio=&quot;4 2 
1&quot;/&gt;
+          &lt;to uri=&quot;mock:x&quot;/&gt;
+          &lt;to uri=&quot;mock:y&quot;/&gt;
+          &lt;to uri=&quot;mock:z&quot;/&gt;
       &lt;/loadBalance&gt;
     &lt;/route&gt;
-</pre>
+]]></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">
-<pre class="brush: java; gutter: false; theme: Default" 
style="font-size:12px;">// round-robin
-from("direct:start")
-    .loadBalance().weighted(true, "4:2:1" distributionRatioDelimiter=":")
-    .to("mock:x", "mock:y", "mock:z");
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[// round-robin
+from(&quot;direct:start&quot;)
+    .loadBalance().weighted(true, &quot;4:2:1&quot; 
distributionRatioDelimiter=&quot;:&quot;)
+    .to(&quot;mock:x&quot;, &quot;mock:y&quot;, &quot;mock:z&quot;);
 
 //random
-from("direct:start")
-    .loadBalance().weighted(false, "4,2,1")
-    .to("mock:x", "mock:y", "mock:z");
-</pre>
+from(&quot;direct:start&quot;)
+    .loadBalance().weighted(false, &quot;4,2,1&quot;)
+    .to(&quot;mock:x&quot;, &quot;mock:y&quot;, &quot;mock:z&quot;);
+]]></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">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">    &lt;route&gt;
-      &lt;from uri="direct:start"/&gt;
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[    &lt;route&gt;
+      &lt;from uri=&quot;direct:start&quot;/&gt;
       &lt;loadBalance&gt;
-        &lt;weighted roundRobin="false" distributionRatio="4-2-1" 
distributionRatioDelimiter="-" /&gt;
-          &lt;to uri="mock:x"/&gt;
-          &lt;to uri="mock:y"/&gt;
-          &lt;to uri="mock:z"/&gt;
+        &lt;weighted roundRobin=&quot;false&quot; 
distributionRatio=&quot;4-2-1&quot; distributionRatioDelimiter=&quot;-&quot; 
/&gt;
+          &lt;to uri=&quot;mock:x&quot;/&gt;
+          &lt;to uri=&quot;mock:y&quot;/&gt;
+          &lt;to uri=&quot;mock:z&quot;/&gt;
       &lt;/loadBalance&gt;
     &lt;/route&gt;
-</pre>
+]]></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(&quot;direct:start&quot;)
@@ -217,7 +217,7 @@ from(&quot;direct:start&quot;)
     .loadBalance(new MyLoadBalancer())
     .to(&quot;mock:x&quot;, &quot;mock:y&quot;, &quot;mock:z&quot;);
 ]]></script>
-</div></div><p>And the same example using XML DSL:</p><div class="code panel 
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</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[
 &lt;!-- this is the implementation of our custom load balancer --&gt;
 &lt;bean id=&quot;myBalancer&quot; 
class=&quot;org.apache.camel.processor.CustomLoadBalanceTest$MyLoadBalancer&quot;/&gt;
@@ -236,14 +236,14 @@ from(&quot;direct:start&quot;)
   &lt;/route&gt;
 &lt;/camelContext&gt;
 ]]></script>
-</div></div><p>Notice in the XML DSL above we use &lt;custom&gt; which is only 
available in <strong>Camel 2.8</strong> onwards. In older releases you would 
have to do as follows instead:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">      &lt;loadBalance ref="myBalancer"&gt;
+</div></div>Notice in the XML DSL above we use &lt;custom&gt; 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[      &lt;loadBalance 
ref=&quot;myBalancer&quot;&gt;
         &lt;!-- these are the endpoints to balancer --&gt;
-        &lt;to uri="mock:x"/&gt;
-        &lt;to uri="mock:y"/&gt;
-        &lt;to uri="mock:z"/&gt;
+        &lt;to uri=&quot;mock:x&quot;/&gt;
+        &lt;to uri=&quot;mock:y&quot;/&gt;
+        &lt;to uri=&quot;mock:z&quot;/&gt;
       &lt;/loadBalance&gt;
-</pre>
+]]></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 {
@@ -267,23 +267,23 @@ public static class MyLoadBalancer exten
 }
 ]]></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>An example using Java DSL:</p><div class="code panel 
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" 
style="font-size:12px;">from("direct:start").loadBalance()
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[from(&quot;direct:start&quot;).loadBalance()
        .circuitBreaker(2, 1000L, MyCustomException.class)
-    .to("mock:result");
-</pre>
+    .to(&quot;mock:result&quot;);
+]]></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">
-<pre class="brush: xml; gutter: false; theme: Default" 
style="font-size:12px;">&lt;camelContext id="camel" 
xmlns="http://camel.apache.org/schema/spring"&gt;
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camelContext id=&quot;camel&quot; 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
        &lt;route&gt;
-    &lt;from uri="direct:start"/&gt;
+    &lt;from uri=&quot;direct:start&quot;/&gt;
     &lt;loadBalance&gt;
-        &lt;circuitBreaker threshold="2" halfOpenAfter="1000"&gt;
+        &lt;circuitBreaker threshold=&quot;2&quot; 
halfOpenAfter=&quot;1000&quot;&gt;
             &lt;exception&gt;MyCustomException&lt;/exception&gt;
         &lt;/circuitBreaker&gt;
-        &lt;to uri="mock:result"/&gt;
+        &lt;to uri=&quot;mock:result&quot;/&gt;
     &lt;/loadBalance&gt;
 &lt;/route&gt;
 &lt;/camelContext&gt;
-</pre>
+]]></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>
@@ -292,7 +292,7 @@ public static class MyLoadBalancer exten
           <div class="navigation">
             <div class="navigation_top">
                 <!-- NavigationBar -->
-<div class="navigation_bottom" id="navigation_bottom"><h3 
id="Navigation-Overviewhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49132";><a
 shape="rect" href="overview.html">Overview</a></h3><ul 
class="alternate"><li><a shape="rect" href="index.html">Home</a></li><li><a 
shape="rect" href="download.html">Download</a></li><li><a shape="rect" 
href="getting-started.html">Getting Started</a></li><li><a shape="rect" 
href="faq.html">FAQ</a></li></ul><h3 
id="Navigation-Documentationhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49534";><a
 shape="rect" href="documentation.html">Documentation</a></h3><ul 
class="alternate"><li><a shape="rect" href="user-guide.html">User 
Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a 
shape="rect" href="books.html">Books</a></li><li><a shape="rect" 
href="tutorials.html">Tutorials</a></li><li><a shape="rect" 
href="examples.html">Examples</a></li><li><a shape="rect" 
href="cookbook.html">Cookbook</a></li>
 <li><a shape="rect" href="architecture.html">Architecture</a></li><li><a 
shape="rect" href="enterprise-integration-patterns.html">Enterprise Integration 
Patterns</a></li><li><a shape="rect" href="dsl.html">DSL</a></li><li><a 
shape="rect" href="components.html">Components</a></li><li><a shape="rect" 
href="data-format.html">Data Format</a></li><li><a shape="rect" 
href="languages.html">Languages</a></li><li><a shape="rect" 
href="security.html">Security</a></li><li><a shape="rect" 
href="security-advisories.html">Security Advisories</a></li></ul><h3 
id="Navigation-Search">Search</h3><form 
enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" 
action="http://www.google.com/cse";>
+<div class="navigation_bottom" id="navigation_bottom"><h3 
id="Navigation-Overview"><a shape="rect" 
href="overview.html">Overview</a></h3><ul class="alternate"><li><a shape="rect" 
href="index.html">Home</a></li><li><a shape="rect" 
href="download.html">Download</a></li><li><a shape="rect" 
href="getting-started.html">Getting Started</a></li><li><a shape="rect" 
href="faq.html">FAQ</a></li></ul><h3 id="Navigation-Documentation"><a 
shape="rect" href="documentation.html">Documentation</a></h3><ul 
class="alternate"><li><a shape="rect" href="user-guide.html">User 
Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a 
shape="rect" href="books.html">Books</a></li><li><a shape="rect" 
href="tutorials.html">Tutorials</a></li><li><a shape="rect" 
href="examples.html">Examples</a></li><li><a shape="rect" 
href="cookbook.html">Cookbook</a></li><li><a shape="rect" 
href="architecture.html">Architecture</a></li><li><a shape="rect" 
href="enterprise-integration-patterns.html">Enterprise
  Integration Patterns</a></li><li><a shape="rect" 
href="dsl.html">DSL</a></li><li><a shape="rect" 
href="components.html">Components</a></li><li><a shape="rect" 
href="data-format.html">Data Format</a></li><li><a shape="rect" 
href="languages.html">Languages</a></li><li><a shape="rect" 
href="security.html">Security</a></li><li><a shape="rect" 
href="security-advisories.html">Security Advisories</a></li></ul><h3 
id="Navigation-Search">Search</h3><form 
enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" 
action="http://www.google.com/cse";>
   <div>
     <input type="hidden" name="cx" value="007878419884033443453:m5nhvy4hmyq">
     <input type="hidden" name="ie" value="UTF-8">
@@ -300,7 +300,7 @@ public static class MyLoadBalancer exten
     <input type="submit" name="sa" value="Search">
   </div>
 </form>
-<script type="text/javascript" 
src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en";></script><h3
 
id="Navigation-Communityhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49115";><a
 shape="rect" href="community.html">Community</a></h3><ul 
class="alternate"><li><a shape="rect" 
href="support.html">Support</a></li><li><a shape="rect" 
href="contributing.html">Contributing</a></li><li><a shape="rect" 
href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" 
href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" 
href="user-stories.html">User Stories</a></li><li><a shape="rect" 
href="news.html">News</a></li><li><a shape="rect" 
href="articles.html">Articles</a></li><li><a shape="rect" 
href="site.html">Site</a></li><li><a shape="rect" 
href="team.html">Team</a></li><li><a shape="rect" class="external-link" 
href="http://camel-extra.googlecode.com/"; rel="nofollow">Camel 
Extra</a></li></ul><h3 id="Navigation-Developershttps://cwi
 ki.apache.org/confluence/pages/viewpage.action?pageId=49124"><a shape="rect" 
href="developers.html">Developers</a></h3><ul class="alternate"><li><a 
shape="rect" href="developers.html">Developer Guide</a></li><li><a shape="rect" 
href="source.html">Source</a></li><li><a shape="rect" 
href="building.html">Building</a></li><li><a shape="rect" 
href="javadoc.html">JavaDoc</a></li><li><a shape="rect" 
href="irc-room.html">IRC Room</a></li></ul><h3 
id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul 
class="alternate"><li><a shape="rect" class="external-link" 
href="http://www.apache.org/licenses/";>License</a></li><li><a shape="rect" 
class="external-link" 
href="http://www.apache.org/foundation/sponsorship.html";>Sponsorship</a></li><li><a
 shape="rect" class="external-link" 
href="http://www.apache.org/foundation/thanks.html";>Thanks</a></li><li><a 
shape="rect" class="external-link" 
href="http://www.apache.org/security/";>Security</a></li></ul></div>
+<script type="text/javascript" 
src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en";></script><h3
 id="Navigation-Community"><a shape="rect" 
href="community.html">Community</a></h3><ul class="alternate"><li><a 
shape="rect" href="support.html">Support</a></li><li><a shape="rect" 
href="contributing.html">Contributing</a></li><li><a shape="rect" 
href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" 
href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" 
href="user-stories.html">User Stories</a></li><li><a shape="rect" 
href="news.html">News</a></li><li><a shape="rect" 
href="articles.html">Articles</a></li><li><a shape="rect" 
href="site.html">Site</a></li><li><a shape="rect" 
href="team.html">Team</a></li><li><a shape="rect" class="external-link" 
href="http://camel-extra.googlecode.com/"; rel="nofollow">Camel 
Extra</a></li></ul><h3 id="Navigation-Developers"><a shape="rect" 
href="developers.html">Developers</a></h3><ul class="alternate"
 ><li><a shape="rect" href="developers.html">Developer Guide</a></li><li><a 
 >shape="rect" href="source.html">Source</a></li><li><a shape="rect" 
 >href="building.html">Building</a></li><li><a shape="rect" 
 >href="javadoc.html">JavaDoc</a></li><li><a shape="rect" 
 >href="irc-room.html">IRC Room</a></li></ul><h3 
 >id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul 
 >class="alternate"><li><a shape="rect" class="external-link" 
 >href="http://www.apache.org/licenses/";>License</a></li><li><a shape="rect" 
 >class="external-link" 
 >href="http://www.apache.org/foundation/sponsorship.html";>Sponsorship</a></li><li><a
 > shape="rect" class="external-link" 
 >href="http://www.apache.org/foundation/thanks.html";>Thanks</a></li><li><a 
 >shape="rect" class="external-link" 
 >href="http://www.apache.org/security/";>Security</a></li></ul></div>
                 <!-- NavigationBar -->
             </div>
           </div>


Reply via email to