Path: redb-route/redb.Route/Processors/ResumePoints.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/Processors/ResumePoints.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Processors;
///
/// Where routing picks up after a failure an OnException ... Continued() handler suppressed (Apache Camel's
/// continued(true)).
///
/// Camel attaches its error handler to every step, so a continued failure returns to the pipeline that was running it
/// and the pipeline moves on to the next step by itself. Here the handler wraps the whole route, and by the time it runs
/// the stack that knew where the failure happened is gone: every pipeline the exception unwinds through records the step
/// it stopped at — innermost first — and the handler replays the rest of them in that order.
///
///
/// The points belong to one failure: another failure starts its own list, so a set nobody replayed cannot be taken for
/// somebody else's. Work that must not be replayed — a transacted block that rolled back, a DoTry body whose
/// failure was caught — is forgotten by the step that swallowed it.
///
///
internal sealed class ResumePoints
{
/// Exchange property holding the points. Owned by the exchange: copies do not inherit it.
internal const string PropertyKey = "__redb_resume";
private readonly List<(PipelineProcessor Pipeline, int NextIndex)> _points = [];
private ResumePoints(Exception failure) => Failure = failure;
private Exception Failure { get; }
/// Remembers that stopped at minus one.
internal static void Record(IExchange exchange, Exception failure, PipelineProcessor pipeline, int nextIndex)
{
var points = Of(exchange, failure);
if (points is null)
{
points = new ResumePoints(failure);
exchange.Properties[PropertyKey] = points;
}
points._points.Add((pipeline, nextIndex));
}
///
/// Forgets what has been recorded for this failure so far: the steps it covers are not to be replayed. A transacted
/// block that rolled back and a caught DoTry body use it — what they did is undone or deliberately abandoned.
///
internal static void Forget(IExchange exchange, Exception failure) => Of(exchange, failure)?._points.Clear();
///
/// Replays the remaining steps of every pipeline the failure unwound through, innermost first. A step that fails
/// again throws from here, and the caller — the route's exception handler — matches it against its handlers anew.
///
internal static async Task ResumeAsync(IExchange exchange, Exception failure, CancellationToken ct)
{
if (Of(exchange, failure) is not { } points)
return;
exchange.Properties.Remove(PropertyKey);
foreach (var (pipeline, nextIndex) in points._points)
{
if (exchange.IsStopped)
break;
await pipeline.ProcessFrom(exchange, nextIndex, ct).ConfigureAwait(false);
}
}
private static ResumePoints? Of(IExchange exchange, Exception failure) =>
exchange.Properties.TryGetValue(PropertyKey, out var value)
&& value is ResumePoints points && ReferenceEquals(points.Failure, failure)
? points
: null;
}