public class CuratorMultiMasterLeaderRoutePolicy extends org.apache.camel.support.RoutePolicySupport implements ElectionWatcher, org.apache.camel.NonManagedService
CuratorMultiMasterLeaderRoutePolicy
uses Apache Curator InterProcessSemaphoreV2 receipe to implement the behavior of having
at multiple active instances 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 receipe 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 |
---|
CuratorMultiMasterLeaderRoutePolicy(String uri) |
CuratorMultiMasterLeaderRoutePolicy(String uri,
int enabledCount) |
Modifier and Type | Method and Description |
---|---|
protected void |
doShutdown() |
void |
electionResultChanged()
This method is called when there is a potential change to the master.
|
CuratorMultiMasterLeaderElection |
getElection() |
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 CuratorMultiMasterLeaderRoutePolicy(String uri, int enabledCount)
public CuratorMultiMasterLeaderRoutePolicy(String uri)
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
protected void doShutdown() throws Exception
doShutdown
in class org.apache.camel.support.ServiceSupport
Exception
public CuratorMultiMasterLeaderElection getElection()
Apache Camel