Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Camel has out of the box the following policies:

Policy

Description

Round Robin

The exchanges is selected in a round robin fashion. This is a well known and classic policy. This spreads the load even.

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 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 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.

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.

...

Using Weighted round-robin & random load balancing

In Camel 2.5
An example using Java DSL:

Code Block

ArrayList<integer> distributionRatio = new ArrayList<integer>();
distributionRatio.add(4);
distributionRatio.add(2);
distributionRatio.add(1);

// round-robin
from("direct:start")
    .loadBalance().weighted(true, distributionRatio)
    .to("mock:x", "mock:y", "mock:z");

//random
from("direct:start")
    .loadBalance().weighted(false, distributionRatio)
    .to("mock:x", "mock:y", "mock:z");

And the same example using Spring XML:

Code Block
    <route>
      <from uri="direct:start"/>
      <loadBalance>
        <weighted roundRobin="false" distributionRatio="4 2 1"/>
          <to uri="mock:x"/>
          <to uri="mock:y"/>
          <to uri="mock:z"/>
      </loadBalance>
    </route>
  • As of Camel 2.6*
    An example using Java DSL:
    Code Block
    // round-robin
    from("direct:start")
        .loadBalance().weighted(true, "4:2:1")
        .to("mock:x", "mock:y", "mock:z");
    
    //random
    from("direct:start")
        .loadBalance().weighted(false, "4,2,1", ",")
        .to("mock:x", "mock:y", "mock:z");
    

...