Path: redb-route/redb.Route/Abstractions/IRouteLifecycleListener.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/IRouteLifecycleListener.cs
----
namespace redb.Route.Abstractions;
///
/// Receives lifecycle events from when routes change state.
/// All methods have default no-op implementations — override only what you need.
///
public interface IRouteLifecycleListener
{
/// Fired after a route has been started and is processing exchanges.
Task OnRouteStarted(string routeId, CancellationToken ct) => Task.CompletedTask;
/// Fired after a route has been stopped.
Task OnRouteStopped(string routeId, CancellationToken ct) => Task.CompletedTask;
/// Fired when a route enters the Suspending state (drain starting).
Task OnRouteSuspending(string routeId, CancellationToken ct) => Task.CompletedTask;
/// Fired when a route fails to start or encounters a fatal error.
Task OnRouteErrored(string routeId, Exception ex, CancellationToken ct) => Task.CompletedTask;
/// Fired when an exchange times out (per-exchange processing timeout from Phase 5).
Task OnExchangeTimedOut(string routeId, string exchangeId, TimeSpan elapsed, CancellationToken ct) => Task.CompletedTask;
///
/// Fired when a supervised connection of an endpoint changes: lost, a reconnect attempt failed, restored. The
/// listener gets the event from the context's queue after the change, so it cannot hold up or break the reconnect; an
/// exception it throws is logged. React with what the context already offers: alert, or stop, restart or fail the
/// route (controlbus:route, ). Do not resend messages from here: a send that failed
/// on a lost connection may have arrived.
///
Task OnConnectionEvent(Core.ConnectionEvent connectionEvent, CancellationToken ct) => Task.CompletedTask;
// ── Exchange-level events (NotifyBuilder / test-kit seam) ──
/// Fired when an exchange enters a route's pipeline, before any step runs.
Task OnExchangeReceived(string routeId, IExchange exchange, CancellationToken ct) => Task.CompletedTask;
///
/// Fired after an exchange has been fully processed by a route and no exception propagated
/// (an error caught and marked handled by error handling counts as completed).
///
Task OnExchangeCompleted(string routeId, IExchange exchange, CancellationToken ct) => Task.CompletedTask;
/// Fired when an exchange escapes a route's pipeline with an exception (error handling declined or rethrew it).
Task OnExchangeFailed(string routeId, IExchange exchange, Exception exception, CancellationToken ct) => Task.CompletedTask;
// ── Context-level events ──
/// Fired before the context starts compiling and starting routes.
Task OnContextStarting(IRouteContext context, CancellationToken ct) => Task.CompletedTask;
/// Fired after the context has started all auto-start routes.
Task OnContextStarted(IRouteContext context, CancellationToken ct) => Task.CompletedTask;
/// Fired before the context begins stopping routes.
Task OnContextStopping(IRouteContext context, CancellationToken ct) => Task.CompletedTask;
/// Fired after the context has stopped all routes and cleaned up.
Task OnContextStopped(IRouteContext context, CancellationToken ct) => Task.CompletedTask;
}