Class ClusteredRoutePolicy
Route policy that ensures only one node in the cluster runs the route consumer.
Uses with TTL-based expiry and epoch fencing.
Background watch loop: if the lock is acquired → consumer starts; if lost → consumer stops;
non-leaders periodically attempt to acquire the lock.
public sealed class ClusteredRoutePolicy : RoutePolicySupport, IRoutePolicy
Inheritance
Implements
Inherited Members
Methods
Configure(Action<ClusteredRoutePolicyOptions>, IDistributedLock, IOptions<ClusterOptions>, ILoggerFactory?)
Full control via options callback.
public static ClusteredRoutePolicy Configure(Action<ClusteredRoutePolicyOptions> configure, IDistributedLock distributedLock, IOptions<ClusterOptions> clusterOptions, ILoggerFactory? loggerFactory = null)
Default(IDistributedLock, IOptions<ClusterOptions>, ILoggerFactory?)
Lock = "route:{routeId}", group from .
public static ClusteredRoutePolicy Default(IDistributedLock distributedLock, IOptions<ClusterOptions> clusterOptions, ILoggerFactory? loggerFactory = null)
ForLock(string, IDistributedLock, IOptions<ClusterOptions>, ILoggerFactory?)
Shared lock: multiple routes compete for one lock — only one consumer runs at a time.
public static ClusteredRoutePolicy ForLock(string lockName, IDistributedLock distributedLock, IOptions<ClusterOptions> clusterOptions, ILoggerFactory? loggerFactory = null)
ForNamespace(string, IDistributedLock, IOptions<ClusterOptions>, ILoggerFactory?)
Lock = "{namespace}:{routeId}". Logical grouping for naming isolation.
public static ClusteredRoutePolicy ForNamespace(string ns, IDistributedLock distributedLock, IOptions<ClusterOptions> clusterOptions, ILoggerFactory? loggerFactory = null)
GetMetadata()
Returns policy-specific metadata for observability (UI, API, diagnostics).
public override IReadOnlyDictionary<string, object>? GetMetadata()
OnInit(IRouteContext, CompiledRoute, CancellationToken)
Called once after the route is compiled but before consumers start.
public override Task OnInit(IRouteContext context, CompiledRoute route, CancellationToken ct)
OnRemove(IRouteContext, CompiledRoute, CancellationToken)
Called when the route is being removed from the context (final cleanup).
public override Task OnRemove(IRouteContext context, CompiledRoute route, CancellationToken ct)
OnResume(IRouteContext, CompiledRoute, CancellationToken)
Called when the route is being resumed after suspension.
public override Task OnResume(IRouteContext context, CompiledRoute route, CancellationToken ct)
OnStart(IRouteContext, CompiledRoute, CancellationToken)
Called before the route consumer is started. Throw to prevent startup.
public override Task OnStart(IRouteContext context, CompiledRoute route, CancellationToken ct)
OnStop(IRouteContext, CompiledRoute, CancellationToken)
Called after the route consumer has been stopped.
public override Task OnStop(IRouteContext context, CompiledRoute route, CancellationToken ct)
OnSuspend(IRouteContext, CompiledRoute, CancellationToken)
Called when the route is being suspended (drain starting).
public override Task OnSuspend(IRouteContext context, CompiledRoute route, CancellationToken ct)