Path: redb-route/redb.Route/Processors/MessageHistoryProcessor.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/MessageHistoryProcessor.cs
----
using System.Diagnostics;
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Processors;
///
/// Wraps a single route node so that, as the exchange passes through, a
/// (route id, node id, node label, elapsed ms) is appended to the exchange's message history. Applied at
/// compile time by when message history is enabled — the runtime
/// half of the Apache Camel Message History EIP.
///
/// The elapsed time is recorded in a finally, so a node that throws still leaves a history entry —
/// which is exactly what the failure dump needs to point at the step that failed.
///
///
internal sealed class MessageHistoryProcessor : IProcessor
{
private readonly IProcessor _inner;
private readonly string _routeId;
private readonly string _nodeId;
private readonly string _label;
public MessageHistoryProcessor(IProcessor inner, string routeId, string nodeId, string label)
{
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
_routeId = routeId;
_nodeId = nodeId;
_label = label;
}
///
public async Task Process(IExchange exchange, CancellationToken ct = default)
{
var start = Stopwatch.GetTimestamp();
try
{
await _inner.Process(exchange, ct).ConfigureAwait(false);
}
finally
{
var elapsedMs = Stopwatch.GetElapsedTime(start).TotalMilliseconds;
MessageHistory.Append(exchange, new MessageHistoryEntry(_routeId, _nodeId, _label, elapsedMs));
}
}
}