...
Wiki Markup |
---|
{snippet:id=example|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoadBalanceTest.java} |
...
Code Block | ||
---|---|---|
| ||
<bean id = "roundRobinRef" class="org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer" /> <camelContext id="camel" xmlns="http://activemqcamel.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <loadBalance ref="roundRobinRef"> <to uri="mock:x"/> <to uri="mock:y"/> <to uri="mock:z"/> </loadBalance> </route> </camelContext> |
...
Code Block | ||
---|---|---|
| ||
<camelContext id="camel" xmlns="http://activemqcamel.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <loadBalance> <roundRobin/> <!-- This only support for Camel 1.5 --> <to uri="mock:x"/> <to uri="mock:y"/> <to uri="mock:z"/> </loadBalance> </route> </camelContext> |
So the above example will load balance requests from direct:start to one of the available mock endpoint instances, in this case using a round robbin policy.
For further examples of this pattern in use you could look at the junit test case
Build in load balancing policies
Camel has out of the box the following policies:
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) |
...