public class ZooKeeperRoutePolicy extends org.apache.camel.support.RoutePolicySupport implements ElectionWatcher, org.apache.camel.NonManagedService
ZooKeeperRoutePolicy
uses the leader election capabilities of a
ZooKeeper cluster to control how routes are enabled. It is typically used in
fail-over scenarios controlling identical instances of a route across a
cluster of Camel based servers.
The policy is configured with a 'top n' number of routes that should be allowed to start, for a master/slave scenario this would be 1. Each instance of the policy will execute the election algorithm to obtain its position in the hierarchy of servers, if it is within the 'top n' servers then the policy is enabled and exchanges can be processed by the route. If not it waits for a change in the leader hierarchy and then reruns this scenario to see if it is now in the top n.
All instances of the policy must also be configured with the same path on the ZooKeeper cluster where the election will be carried out. It is good practice for this to indicate the application e.g. /someapplication/someroute/ note that these nodes should exist before using the policy.
See for more on how Leader election is archived with ZooKeeper.
Constructor and Description |
---|
ZooKeeperRoutePolicy(String uri,
int enabledCount) |
ZooKeeperRoutePolicy(ZooKeeperElection election) |
Modifier and Type | Method and Description |
---|---|
void |
electionResultChanged()
This method is called when there is a potential change to the master.
|
boolean |
isShouldStopConsumer() |
void |
onExchangeBegin(org.apache.camel.Route route,
org.apache.camel.Exchange exchange) |
void |
setShouldStopConsumer(boolean shouldStopConsumer) |
doStart, doStop, getExceptionHandler, handleException, onExchangeDone, onInit, onRemove, onResume, onStart, onStop, onSuspend, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, suspendRoute, suspendRoute
public ZooKeeperRoutePolicy(String uri, int enabledCount)
public ZooKeeperRoutePolicy(ZooKeeperElection election)
public void onExchangeBegin(org.apache.camel.Route route, org.apache.camel.Exchange exchange)
onExchangeBegin
in interface org.apache.camel.spi.RoutePolicy
onExchangeBegin
in class org.apache.camel.support.RoutePolicySupport
public void electionResultChanged()
ElectionWatcher
electionResultChanged
in interface ElectionWatcher
public boolean isShouldStopConsumer()
public void setShouldStopConsumer(boolean shouldStopConsumer)
Apache Camel