Class RouteContext
Central runtime context: component registry, endpoint cache, route compilation and lifecycle,
properties, service locator, and three-tier exception handling.
Replaces the former RouteEngine — like Apache Camel's CamelContext, this is the single
entry point that owns routes from definition through execution.
public class RouteContext : IRouteContext, IDisposable, IAsyncDisposable
Inheritance
Implements
Properties
ErrorHandler
Gets or sets the context's error handler — Apache Camel's context-level error handler: on every route, the
public IErrorHandler? ErrorHandler { get; set; }
InflightRepository
Repository tracking all in-flight exchanges across routes in this context.
public IInflightRepository InflightRepository { get; }
IsContextIdGenerated
Whether was generated (a new GUID) rather than given: then it differs on every start and
public bool IsContextIdGenerated { get; }
OnBeforeRoutesStart
Optional callback invoked after routes are compiled but before consumers are started.
public Func<IReadOnlyList<CompiledRoute>, Task>? OnBeforeRoutesStart { get; set; }
Routes
Gets the compiled routes (available after Start).
public IReadOnlyList<CompiledRoute> Routes { get; }
this[string]
Gets or sets a context-level property by key. Returns null if not found.
public object? this[string key] { get; set; }
Methods
AddComponent(IComponent)
Registers a component for its URI scheme.
public void AddComponent(IComponent component)
AddGlobalExceptionHandler(Type, IProcessor)
Registers a global exception handler for the specified exception type (non-generic overload).
public void AddGlobalExceptionHandler(Type exceptionType, IProcessor processor)
AddGlobalExceptionHandler<TException>(IProcessor)
Registers a global exception handler for a specific exception type: on every route, for a failure of this type
public void AddGlobalExceptionHandler<TException>(IProcessor processor) where TException : Exception
AddLifecycleListener(IRouteLifecycleListener)
Registers a lifecycle listener for route state change notifications.
public IRouteContext AddLifecycleListener(IRouteLifecycleListener listener)
AddLocalExceptionHandler(string, Type, IProcessor)
Registers a local exception handler for a specific route and exception type: checked before the global
public void AddLocalExceptionHandler(string routeId, Type exceptionType, IProcessor processor)
AddRouteConfiguration(Action<RouteConfigurationDefinition>)
Adds the default route configuration with an inline action — the inline form of a
public RouteContext AddRouteConfiguration(Action<RouteConfigurationDefinition> configure)
AddRouteConfiguration(string, Action<RouteConfigurationDefinition>)
Adds a route configuration with an id, for the routes that name it with .RouteConfigurationId("id").
public RouteContext AddRouteConfiguration(string id, Action<RouteConfigurationDefinition> configure)
AddRoutePolicyFactory(IRoutePolicyFactory)
Registers a factory that can create instances for routes
public IRouteContext AddRoutePolicyFactory(IRoutePolicyFactory factory)
AddRoutes(Action<InlineRouteBuilder>)
Adds routes using an inline configure action.
public RouteContext AddRoutes(Action<InlineRouteBuilder> configure)
AddRoutes(IEnumerable<Assembly>, Func<Type, bool>)
with a filter choosing which builders to take — the place for a condition
public RouteContext AddRoutes(IEnumerable<Assembly> assemblies, Func<Type, bool> filter)
AddRoutes(params Assembly[])
Adds every route builder of assemblies: each public, non-abstract, closed class deriving from
public RouteContext AddRoutes(params Assembly[] assemblies)
AddRoutes(RouteBuilder)
Adds a route builder containing route definitions.
public RouteContext AddRoutes(RouteBuilder builder)
AddService(Type, object)
Registers a service instance by type.
public void AddService(Type serviceType, object service)
AddThreadPoolProfile(string, ThreadPoolProfile)
Registers a named thread pool profile that a detached step (WireTap, asynchronous OnCompletion)
public void AddThreadPoolProfile(string name, ThreadPoolProfile profile)
AddToRegistry(string, object)
Stores a named object in the registry (factories, shared state, etc.).
public IRouteContext AddToRegistry(string key, object value)
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or
public ValueTask DisposeAsync()
GetComponent<T>(string?)
Gets a component by type, optionally filtering by scheme name.
public T? GetComponent<T>(string? scheme = null) where T : class, IComponent
GetComponentNames()
Returns a snapshot of all registered component scheme names.
public IReadOnlyList<string> GetComponentNames()
GetEndpoint(string)
Resolves or creates an endpoint by URI string. Caches by NormalizedKey.
public IEndpoint GetEndpoint(string uri)
GetEndpoints()
Returns a snapshot of all currently cached endpoints.
public IReadOnlyList<IEndpoint> GetEndpoints()
GetFromRegistry<T>(string)
Retrieves a typed object from the registry.
public T? GetFromRegistry<T>(string key)
GetProperty<T>(string)
Gets a typed property value with automatic conversion.
public T? GetProperty<T>(string key)
GetReplayMarkers()
Lists every compiled replay marker as (routeId, markerName). Lets the platform show
public IReadOnlyCollection<(string RouteId, string MarkerName)> GetReplayMarkers()
GetRoute(string)
Gets a compiled route by its route ID.
public CompiledRoute? GetRoute(string routeId)
GetRoutePolicy(string)
Returns the effective cluster-policy resolution for a compiled route.
public RoutePolicyDescriptor GetRoutePolicy(string routeId)
GetServiceProvider()
Retrieves the registered , or null if not set.
public IServiceProvider? GetServiceProvider()
GetThreadPoolProfile(string?)
The profile a detached step builds its pool from: the named one, or the context's default when
public ThreadPoolProfile GetThreadPoolProfile(string? name)
HandleException(IExchange, Exception, CancellationToken)
Handles an exception using three-tier search order:
public Task HandleException(IExchange exchange, Exception exception, CancellationToken ct = default)
HasComponent(string)
Returns whether a component with the specified scheme is registered.
public bool HasComponent(string scheme)
HasExceptionRoute<TException>()
Checks whether an exception handler is registered (globally or locally)
public bool HasExceptionRoute<TException>() where TException : Exception
IsErroredRouteUnhealthy(CompiledRoute)
Whether an Errored route of this context makes health Unhealthy rather than Degraded
public bool IsErroredRouteUnhealthy(CompiledRoute route)
RemoveComponent(string)
Removes a component by scheme. Returns true if removed.
public bool RemoveComponent(string scheme)
ReplayAsync(string, string, IExchange, CancellationToken)
Re-runs the tail of a route from a captured checkpoint snapshot. Runs the compiled body of
public Task ReplayAsync(string routeId, string markerName, IExchange snapshot, CancellationToken ct = default)
ResumeRoute(string, CancellationToken)
Resumes a previously stopped/suspended route.
public Task ResumeRoute(string routeId, CancellationToken ct = default)
SetProperty<T>(string, T)
Sets a typed property. Returns this context for chaining.
public IRouteContext SetProperty<T>(string key, T value)
SetServiceProvider(IServiceProvider)
Stores an for DI container integration.
public IRouteContext SetServiceProvider(IServiceProvider serviceProvider)
Start(CancellationToken)
Starts all registered endpoints and consumers. Uses degraded-mode startup:
public Task Start(CancellationToken ct = default)
StartRoute(string, CancellationToken)
Starts an individual route by its route ID.
public Task StartRoute(string routeId, CancellationToken ct = default)
Stop(CancellationToken)
Stops all routes managed by this context.
public Task Stop(CancellationToken ct = default)
StopRoute(string, CancellationToken)
Stops an individual route by its route ID.
public Task StopRoute(string routeId, CancellationToken ct = default)
StopRoute(string, TimeSpan?, CancellationToken)
Stops an individual route by its route ID with an optional timeout override.
public Task StopRoute(string routeId, TimeSpan? timeout, CancellationToken ct = default)
Constructors
RouteContext(IServiceProvider, string?, ILoggerFactory?, RouteEngineOptions?)
Creates a new route context with built-in components (Direct, Timer, Seda, Mock, Log)
RouteContext(string?, ILoggerFactory?, RouteEngineOptions?)
Creates a new route context with built-in components (Direct, Timer, Seda, Mock, Log).