org.apache.camel.component.zookeeper.policy
Class ZooKeeperRoutePolicy

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.RoutePolicySupport
          extended by org.apache.camel.component.zookeeper.policy.ZooKeeperRoutePolicy
All Implemented Interfaces:
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

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.


Field Summary
 
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
 
Constructor Summary
ZooKeeperRoutePolicy(String uri, int enabledCount)
           
 
Method Summary
 boolean isShouldStopConsumer()
           
 void onExchangeBegin(org.apache.camel.Route route, org.apache.camel.Exchange exchange)
           
 void setShouldStopConsumer(boolean shouldStopConsumer)
           
 
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, 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
 

Constructor Detail

ZooKeeperRoutePolicy

public ZooKeeperRoutePolicy(String uri,
                            int enabledCount)
                     throws Exception
Throws:
Exception
Method Detail

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

isShouldStopConsumer

public boolean isShouldStopConsumer()

setShouldStopConsumer

public void setShouldStopConsumer(boolean shouldStopConsumer)


Apache CAMEL