...
Policy | Description |
---|---|
The exchanges is selected in a round robin fashion. This is a well known and classic policy. This spreads the load even. | |
A random endpoint is selected for each exchange | |
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 which sends to all destinations (rather like JMS Topics) | |
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. |
...
The parameters that can be used are
In Camel 2.5
Option | Type | Default | Description |
---|---|---|---|
roundRobin | boolean | false | The default value for round-robin is false. In the absence of this setting or parameter the load balancing algorithm used is random. |
distributionRatio | List<Integer> | none | 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. |
...
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");
|
And the same example using Spring XML:
Code Block | ||||
---|---|---|---|---|
| ||||
<route> <from uri="direct:start"/> <loadBalance> <weighted roundRobin="false" distributionRatio="4,2,1" distributionRatioDelimiter="," /> <to uri="mock:x"/> <to uri="mock:y"/> <to uri="mock:z"/> </loadBalance> </route> |
...