Custom Load Balancer

This EIP allows you to use your own Load Balancer implementation

The Custom Load Balancer EIP supports 1 options which are listed below:

Name Description Default Type


Required Refers to the custom load balancer to lookup from the registry


An example using Java DSL:

    // using our custom load balancer
    .loadBalance(new MyLoadBalancer())
    .to("mock:x", "mock:y", "mock:z");

And the same example using XML DSL:

<!-- this is the implementation of our custom load balancer -->
<bean id="myBalancer" class="org.apache.camel.processor.CustomLoadBalanceTest$MyLoadBalancer"/>

<camelContext xmlns="">
    <from uri="direct:start"/>
      <!-- refer to my custom load balancer -->
      <custom ref="myBalancer"/>
      <!-- these are the endpoints to balancer -->
      <to uri="mock:x"/>
      <to uri="mock:y"/>
      <to uri="mock:z"/>

Notice in the XML DSL above we use <custom> which is only available in Camel 2.8 onwards. In older releases you would have to do as follows instead:

<loadBalance ref="myBalancer">
  <!-- these are the endpoints to balancer -->
  <to uri="mock:x"/>
  <to uri="mock:y"/>
  <to uri="mock:z"/>

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 of a custom load balancer implementation:

public static class MyLoadBalancer extends LoadBalancerSupport {

    public boolean process(Exchange exchange, AsyncCallback callback) {
        String body = exchange.getIn().getBody(String.class);
        try {
            if ("x".equals(body)) {
            } else if ("y".equals(body)) {
            } else {
        } catch (Throwable e) {
        return true;