public class ZooKeeperRoutePolicy extends RoutePolicySupport implements ElectionWatcher, 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.
log
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
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(Route route,
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
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public ZooKeeperRoutePolicy(String uri, int enabledCount)
public ZooKeeperRoutePolicy(ZooKeeperElection election)
public void onExchangeBegin(Route route, Exchange exchange)
RoutePolicy
onExchangeBegin
in interface RoutePolicy
onExchangeBegin
in class RoutePolicySupport
route
- the route where the exchange started fromexchange
- the created exchangepublic void electionResultChanged()
ElectionWatcher
electionResultChanged
in interface ElectionWatcher
public boolean isShouldStopConsumer()
public void setShouldStopConsumer(boolean shouldStopConsumer)
Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.