Path: redb-route/redb.Route/Abstractions/IRoutePolicy.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Abstractions/IRoutePolicy.cs
----
#pragma warning disable CS0619
using redb.Route.Core;
namespace redb.Route.Abstractions;
///
/// Controls route lifecycle and receives per-exchange notifications.
/// Analogous to Apache Camel's RoutePolicy.
/// All methods have default no-op implementations — override only what you need.
///
public interface IRoutePolicy
{
// ── Lifecycle ──
/// Called once after the route is compiled but before consumers start.
Task OnInit(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
/// Called before the route consumer is started. Throw to prevent startup.
Task OnStart(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
/// Called after the route consumer has been stopped.
Task OnStop(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
/// Called when the route is being removed from the context (final cleanup).
Task OnRemove(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
/// Called when the route is being suspended (drain starting).
Task OnSuspend(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
/// Called when the route is being resumed after suspension.
Task OnResume(IRouteContext context, CompiledRoute route, CancellationToken ct) => Task.CompletedTask;
// ── Metadata ──
///
/// Returns policy-specific metadata for observability (UI, API, diagnostics).
/// Keys are policy-defined; values should be JSON-serializable primitives.
///
IReadOnlyDictionary? GetMetadata() => null;
// ── Per-exchange ──
/// Called when an exchange starts processing in this route.
Task OnExchangeBegin(IRouteContext context, IExchange exchange, CancellationToken ct) => Task.CompletedTask;
/// Called when an exchange finishes processing (success or failure).
Task OnExchangeDone(IRouteContext context, IExchange exchange, CancellationToken ct) => Task.CompletedTask;
}