public class CuratorLeaderRoutePolicy extends org.apache.camel.support.RoutePolicySupport implements ElectionWatcher, org.apache.camel.NonManagedService
CuratorLeaderRoutePolicy
uses Apache Curator LeaderElection recipe to implement the behavior of having
at max 1 instance of a route, controlled by a specific policy, running. It is typically used in
fail-over scenarios controlling identical instances of a route across a
cluster of Camel based servers.
The policy affects the normal startup lifecycle of CamelContext and Routes, automatically set autoStart property of routes controlled by this policy to false. After Curator recipe identifies the current Policy instance as the Leader between a set of clients that are competing for the role, it will start the route, and only at that moment the route will start its business. This specific behavior is designed to avoid scenarios where such a policy would kick in only after a route had already been started, with the risk, for consumers for example, that some source event might have already been consumed.
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 |
---|
CuratorLeaderRoutePolicy(CuratorLeaderElection election) |
CuratorLeaderRoutePolicy(String uri) |
Modifier and Type | Method and Description |
---|---|
protected void |
doShutdown() |
void |
electionResultChanged()
This method is called when there is a potential change to the master.
|
void |
onInit(org.apache.camel.Route route) |
doStart, doStop, getExceptionHandler, handleException, onExchangeBegin, onExchangeDone, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
public CuratorLeaderRoutePolicy(String uri)
public CuratorLeaderRoutePolicy(CuratorLeaderElection election)
public void onInit(org.apache.camel.Route route)
onInit
in interface org.apache.camel.spi.RoutePolicy
onInit
in class org.apache.camel.support.RoutePolicySupport
public void electionResultChanged()
ElectionWatcher
electionResultChanged
in interface ElectionWatcher
Apache Camel