Author: buildbot Date: Sun Apr 13 14:19:02 2014 New Revision: 906027 Log: Production update by buildbot for camel
Modified: websites/production/camel/content/cache/main.pageCache websites/production/camel/content/load-balancer.html Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/camel/content/load-balancer.html ============================================================================== --- websites/production/camel/content/load-balancer.html (original) +++ websites/production/camel/content/load-balancer.html Sun Apr 13 14:19:02 2014 @@ -86,44 +86,20 @@ <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.or g/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 res pect 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></tbody></table></div> - - - <div class="aui-message success shadowed information-macro"> +<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="aui-message success shadowed information-macro"> <p class="title">Load balancing HTTP endpoints</p> <span class="aui-icon icon-success">Icon</span> <div class="message-content"> - -<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> + <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><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"> +<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></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ 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"> -<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ -<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> +</div></div><p><strong>Using the Spring configuration</strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <loadBalance> @@ -135,47 +111,21 @@ roundRobin().to("mock:x", &quo </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="aui-message hint shadowed information-macro"> +</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="aui-message hint shadowed information-macro"> <p class="title">Enable stream caching if using streams</p> <span class="aui-icon icon-hint">Icon</span> <div class="message-content"> - -<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> + <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> 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 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> t ry 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 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="aui-message warning shadowed information-macro"> +<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 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-han dler.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 whet her 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 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 b alancer 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="aui-message warning shadowed information-macro"> <p class="title">Redelivery must be enabled</p> <span class="aui-icon icon-warning">Icon</span> <div class="message-content"> - -<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> + <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"> +<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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ from("direct:start") // here we will load balance if IOException was thrown @@ -185,25 +135,16 @@ from("direct:start") .loadBalance().failover(IOException.class) .to("direct:x", "direct:y", "direct:z"); ]]></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"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -// enable redelivery so failover can react +</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"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[// enable redelivery so failover can react errorHandler(defaultErrorHandler().maximumRedeliveries(5)); 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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ - <route errorHandlerRef="myErrorHandler"> +</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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <route errorHandlerRef="myErrorHandler"> <from uri="direct:foo"/> <loadBalance> <failover> @@ -215,12 +156,7 @@ from("direct:foo"). </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"> +</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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ from("direct:start") // Use failover load balancer in stateful round robin mode @@ -230,10 +166,7 @@ from("direct:start") .loadBalance().failover(-1, false, true). to("direct:bad", "direct:bad2", "direct:good", "direct:good2"); ]]></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><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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> @@ -249,55 +182,22 @@ from("direct:start") </loadBalance> </route> ]]></script> -</div></div> - - <div class="aui-message success shadowed information-macro"> +</div></div> <div class="aui-message success shadowed information-macro"> <p class="title">Disabled inheritErrorHandler</p> <span class="aui-icon icon-success">Icon</span> <div class="message-content"> - -<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> + <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="aui-message success shadowed information-macro"> +<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="aui-message success shadowed information-macro"> <p class="title">Disabled inheritErrorHandler</p> <span class="aui-icon icon-success">Icon</span> <div class="message-content"> - -<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> + <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 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="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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -ArrayList<integer> distributionRatio = new ArrayList<integer>(); +<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 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 col span="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" cl ass="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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ArrayList<integer> distributionRatio = new ArrayList<integer>(); distributionRatio.add(4); distributionRatio.add(2); distributionRatio.add(1); @@ -312,12 +212,8 @@ 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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ - <route> +</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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <loadBalance> <weighted roundRobin="false" distributionRatio="4 2 1"/> @@ -327,14 +223,8 @@ from("direct:start") </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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -// round-robin +</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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[// round-robin from("direct:start") .loadBalance().weighted(true, "4:2:1" distributionRatioDelimiter=":") .to("mock:x", "mock:y", "mock:z"); @@ -344,12 +234,8 @@ 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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ - <route> +</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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <loadBalance> <weighted roundRobin="false" distributionRatio="4-2-1" distributionRatioDelimiter="-" /> @@ -359,25 +245,14 @@ from("direct:start") </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"> +</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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ from("direct:start") // using our custom load balancer .loadBalance(new MyLoadBalancer()) .to("mock:x", "mock:y", "mock:z"); ]]></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><p>And the same example using XML DSL:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <!-- this is the implementation of our custom load balancer --> <bean id="myBalancer" class="org.apache.camel.processor.CustomLoadBalanceTest$MyLoadBalancer"/> @@ -396,22 +271,15 @@ from("direct:start") </route> </camelContext> ]]></script> -</div></div> - -<p>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> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ - <loadBalance ref="myBalancer"> +</div></div><p>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><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ <loadBalance ref="myBalancer"> <!-- these are the endpoints to balancer --> <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"> +</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="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ public static class MyLoadBalancer extends LoadBalancerSupport { @@ -433,10 +301,24 @@ public static class MyLoadBalancer exten } } ]]></script> -</div></div> - - -<h4 id="LoadBalancer-UsingThisPattern">Using This Pattern</h4> +</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 the 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 be passed and if the result is success the Circuit Breaker will move 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"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[from("direct:start").loadBalance() + .circuitBreaker(2, 1000L, MyExceptionProcessor.class) + .to("mock:result"); +]]></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="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <loadBalance> + <circuitBreaker threshold="2" halfOpenAfter="1000L"/> + <exception>MyExceptionProcessor</exception> + <to uri="mock:result"/> + </loadBalance> + </route> +</camelContext> +]]></script> +</div></div><p>The above example loads balance requests from <strong><a shape="rect" class="external-link" href="http://directstart" rel="nofollow">direct:start</a></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><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> </td>