...
If you are proxying and load balancing HTTP, then see this page for more details.
...
The round robin load balancer is stateful as it keeps state of which endpoint to use next time.
Using the Fluent Builders Wiki Markup
...
...
The above example loads balance requests from direct:start to one of the available mock endpoint instances, in this case using a round robin policy.
For further examples of this pattern look at this junit test case
...
If you use streaming then you should enable Stream caching when using the failover load balancer. This is needed so the stream can be re-read after failing over to the next processor.
...
Camel 2.3 onwards behavior
The failover
load balancer now supports round robin mode, which allows you to failover in a round robin fashion. See the roundRobin
option.
...
...
In Camel 2.2 or older the failover load balancer requires you have enabled Camel Error Handler to use redelivery. In Camel 2.3 onwards this is not required as such, as you can mix and match. See the inheritErrorHandler
option.
Here is a sample to failover only if a IOException
related exception was thrown: Wiki Markup
...
...
Using failover in Spring DSL
Failover can also be used from Spring DSL and you configure it as:
...
...
Using failover in round robin mode
An example using Java DSL: Wiki Markup : Wiki Markup
...
...
You can configure inheritErrorHandler=false
if you want to failover to the next endpoint as fast as possible. By disabling the Error Handler you ensure it does not intervene which allows the failover
load balancer to handle failover asap. By also enabling roundRobin
mode, then it will keep retrying until it success. You can then configure the maximumFailoverAttempts
option to a high value to let it eventually exhaust (give up) and fail.
Weighted Round-Robin and Random Load Balancing
...
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.
...
...
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.
The parameters that can be used are
...
An example using Java DSL:
...
...
And the same example using Spring XML:
...
:
...
Available In Camel 2.6
An example using Java DSL:
...
And the same example using Spring XML:
...
...
Custom Load Balancer
You can use a custom load balancer (eg your own implementation) also.
An example using Java DSL: Wiki Markup : Wiki Markup
...
...
To implement a custom load balancer you can extend some support classes such as LoadBalancerSupport
and SimpleLoadBalancerSupport
. The former supports the asynchronous routing engine, and the latter does not. Here is an example: Wiki Markup
Circuit Breaker
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 errorclosed state, or to open state if there was an error.
When the circuit breaker is closed, it will throw a java.util.concurrent.RejectedExecutionException
. This can then be caught to provide an alternate path for processing exchanges.
An example using Java DSL:
...
...
And the same example using Spring XML:
...
...
Using This PatternUsing This Pattern Include Page