Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: editorial fixes

...

The Load Balancer Pattern allows you to delegate to one of a number of endpoints using a variety of different load balancing policies.

...

Built-in load balancing policies

Camel has provides the following policies out-of-the-box the following policies:

Policy

Description

Round Robin

The exchanges is are selected from in a round robin fashion. This is a well known and classic policy. This , which spreads the load evenevenly.

Random

A random endpoint is selected for each exchange.

Sticky

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.

Topic

Topic which sends to all destinations (rather like JMS Topics)

Failover

Camel 2.0: In case of failures the exchange is will be tried on the next endpoint.

Weighted Round-Robin

Camel 2.5: 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 round-robin distribution based on weight.

Weighted Random

Camel 2.5: 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 random distribution based on weight.

Custom

Camel 2.8: From Camel 2.8 onwards the preferred way of using a custom Load Balancer is to use this policy, instead of using the @deprecated ref attribute.

Round Robin

Camel 1.x behavior
The round robin load balancer can actually be used to failover with Camel 1.x. This is no longer possible in Camel 2.x as the underlying Error Handler foundation has been significantly overhauled in Camel 2.x. Frankly the round robin load balancer in Camel 1.x was not thought to be used in a failover scenario.

...

of using the @deprecated ref attribute.

Round Robin

The round robin load balancer is not meant to work with failover, for that you should use the dedicated failover load balancer. The round robin load balancer will only change to next endpoint per message.

The round robin load balancer is statefull stateful as it keeps state of which endpoint to use next time.

...

Code Block
languagexml
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:start"/>
    <loadBalance>        
        <roundRobin/>
        <to uri="mock:x"/>        
        <to uri="mock:y"/>       
        <to uri="mock:z"/>                 
    </loadBalance>
  </route>
</camelContext>

So the The above example will load loads balance requests from direct:start to one of the available mock endpoint instances, in this case using a round robbin robin policy.
For further examples of this pattern in use you could look at the this junit test case

Failover

Available as of Camel 2.0
The failover load balancer is capable of trying the next processor in case an Exchange failed with an exception during processing.
You can configure constrain the failover with a list of specific exception to only failover to activate only when one exception of a list you specify occurs. If you do not specify a list any exceptions it exception will failover over any exceptions. It cause fail over to occur. This balancer uses the same strategy for matching exceptions as the Exception Clause does for the onException.

Info
titleEnable stream caching if using streams

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 when after failing over to the next processor.

It has Failover offers the following options:

Option

Type

Default

Description

inheritErrorHandler

boolean

true

Camel 2.3: Whether or not the Error Handler configured on the route should be used or not. You can disable it . Disable this if you want the failover to trigger transfer immediately and failover to the next endpoint. On the other hand, if you have this option enabled, then Camel will first let the Error Handler try to process the message. The Error Handler may have been configured to redelivery redeliver and use delays between attempts. If you have enabled a number of redeliveries then Camel will try to redeliver to the same endpoint, and only failover fail over to the next endpoint, when the Error Handler is exhausted.

maximumFailoverAttempts

int

-1

Camel 2.3: A value to indicate after X failver failover attempts we should exhaust (give up). Use -1 to indicate newer never give up and always continuously try to failover. Use 0 to newer never failover. And use e.g. 3 to failover at most 3 times before giving up. This option can be used whether or not round robin roundRobin is enabled or not.

roundRobin

boolean

false

Camel 2.3: Whether or not the failover load balancer should operate in round robin 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 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 stick to last known good endpoint, it will always pick the next endpoint to use.

Camel 2.2 or older behavior
The current implement implementation of failover load balancer is a uses simple logic which always 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 always start with the first endpoint.

...