Path: redb-route/redb.Route/Processors/UnitOfWorkProcessor.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/UnitOfWorkProcessor.cs ---- using Microsoft.Extensions.Logging; using redb.Route.Abstractions; using redb.Route.Core; namespace redb.Route.Processors; /// /// Opens the exchange's unit of work when it enters its first route and ends it before that route returns to its consumer /// (Apache Camel: the UnitOfWork of the consumer's route, done before the consumer acknowledges). The completions /// registered with have therefore run before the message is acknowledged or /// handed back to the broker, so a redelivery cannot overtake them. /// /// Sits outside every error handler and the route's OnCompletion blocks, and reaches the consumer's verdict: an /// escaping exception is a failure, and so is a normal return with an unhandled failure left on the exchange /// (OnException without Handled) or a rollback-only mark (.RollbackAll()) — /// . A handled failure is a success. A route called with an exchange /// whose unit of work is already open (direct:) passes through. /// /// internal sealed class UnitOfWorkProcessor : IProcessor { private readonly IProcessor _inner; private readonly ILogger? _logger; public UnitOfWorkProcessor(IProcessor inner, ILogger? logger) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); _logger = logger; } public async Task Process(IExchange exchange, CancellationToken ct = default) { var unitOfWork = ExchangeResources.OpenUnitOfWork(exchange); if (unitOfWork is null) { await _inner.Process(exchange, ct).ConfigureAwait(false); return; } try { await _inner.Process(exchange, ct).ConfigureAwait(false); } catch { await unitOfWork.End(exchange, failed: true, _logger).ConfigureAwait(false); throw; } await unitOfWork.End(exchange, exchange.EndedInFailure(), _logger).ConfigureAwait(false); } }