Path: redb-route/redb.Route/Definitions/ResequenceDefinition.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/Definitions/ResequenceDefinition.cs
----
using redb.Route.Abstractions;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Scope-opener definition for the Resequencer EIP. Buffers and reorders incoming
/// exchanges by a sequence key before delivering them to its child outputs.
/// Apache Camel parity: .resequence(...).process(...).end().
/// Inherits the leaf DSL from .
///
public sealed class ResequenceDefinition : RouteDefinitionBase, IRouteScope
{
private readonly Func _keySelector;
private readonly int _batchSize;
private readonly TimeSpan? _timeout;
/// Creates a resequence definition.
internal ResequenceDefinition(Func keySelector, int batchSize, TimeSpan? timeout)
{
ArgumentNullException.ThrowIfNull(keySelector);
if (batchSize <= 0) throw new ArgumentOutOfRangeException(nameof(batchSize));
_keySelector = keySelector;
_batchSize = batchSize;
_timeout = timeout;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
{
IProcessor inner = NodePipeline.Body(context, Outputs);
// Every delivery comes out of the buffer — on a timer, or with exchanges of callers that have already returned —
// and a failure is kept on its exchange, never thrown to the route's error wrappers: the body is wrapped by the
// route's error scope.
inner = (context as Core.RouteContext)?.DetachedErrorScope?.WrapDetached(inner) ?? inner;
return new ResequencerProcessor(inner, _keySelector, _batchSize, _timeout);
}
/// Closes the Resequence scope and returns to the parent route.
public IRouteDefinition EndResequence()
=> (IRouteDefinition)(Parent ?? throw new InvalidOperationException(
"EndResequence() called without a parent route. Ensure Resequence() was called on a route definition."));
///
public IRouteDefinition End() => EndResequence();
}