org.apache.camel.component.zookeeper.policy
Class ZooKeeperRoutePolicy
java.lang.Object
org.apache.camel.support.ServiceSupport
org.apache.camel.impl.RoutePolicySupport
org.apache.camel.component.zookeeper.policy.ZooKeeperRoutePolicy
- All Implemented Interfaces:
- ElectionWatcher, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.RoutePolicy, org.apache.camel.StatefulService, org.apache.camel.SuspendableService
public class ZooKeeperRoutePolicy
- extends org.apache.camel.impl.RoutePolicySupport
- implements ElectionWatcher
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.
Fields inherited from class org.apache.camel.impl.RoutePolicySupport |
log |
Fields inherited from class org.apache.camel.support.ServiceSupport |
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending |
Methods inherited from class org.apache.camel.impl.RoutePolicySupport |
doStart, doStop, getExceptionHandler, handleException, onExchangeDone, onInit, onRemove, onResume, onStart, onStop, onSuspend, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, suspendRoute, suspendRoute |
Methods inherited from class org.apache.camel.support.ServiceSupport |
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ZooKeeperRoutePolicy
public ZooKeeperRoutePolicy(String uri,
int enabledCount)
ZooKeeperRoutePolicy
public ZooKeeperRoutePolicy(ZooKeeperElection election)
onExchangeBegin
public void onExchangeBegin(org.apache.camel.Route route,
org.apache.camel.Exchange exchange)
- Specified by:
onExchangeBegin
in interface org.apache.camel.spi.RoutePolicy
- Overrides:
onExchangeBegin
in class org.apache.camel.impl.RoutePolicySupport
electionResultChanged
public void electionResultChanged()
- Description copied from interface:
ElectionWatcher
- This method is called when there is a potential change to the master.
Implementations should call "isMaster" on their ZookeeperElection
instance to re-validate their status.
- Specified by:
electionResultChanged
in interface ElectionWatcher
isShouldStopConsumer
public boolean isShouldStopConsumer()
setShouldStopConsumer
public void setShouldStopConsumer(boolean shouldStopConsumer)
Apache Camel