Path: redb-route/redb.Route/Definitions/RoutingSlipDefinition.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/RoutingSlipDefinition.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.Expressions;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Routing Slip EIP (Apache Camel parity): routes the exchange through a list of endpoints computed
/// once up front. The slip may be supplied as a factory delegate, an
/// that yields a delimited URI string, or a ${...} template string. Leaf node — no
/// .
///
/// Unlike (which recomputes the next hop per step) the slip is
/// evaluated a single time; unlike (which fans out a copy to
/// each recipient) the slip pipes the same exchange through the endpoints in sequence.
///
///
public sealed class RoutingSlipDefinition : ProcessorDefinition
{
private const string DefaultDelimiter = ",";
private readonly Func> _slipFactory;
private readonly bool _ignoreInvalidEndpoints;
/// Creates a routing slip from a factory that returns the endpoint URIs per exchange.
public RoutingSlipDefinition(Func> slipFactory, bool ignoreInvalidEndpoints = false)
{
_slipFactory = slipFactory ?? throw new ArgumentNullException(nameof(slipFactory));
_ignoreInvalidEndpoints = ignoreInvalidEndpoints;
}
///
/// Creates a routing slip from an that evaluates to a delimited URI
/// string (Camel form routingSlip(header("..."))).
///
public RoutingSlipDefinition(IExpression slip, string uriDelimiter = DefaultDelimiter, bool ignoreInvalidEndpoints = false)
{
ArgumentNullException.ThrowIfNull(slip);
var delimiter = string.IsNullOrEmpty(uriDelimiter) ? DefaultDelimiter : uriDelimiter;
_slipFactory = ex => Split(slip.Evaluate(ex), delimiter);
_ignoreInvalidEndpoints = ignoreInvalidEndpoints;
}
///
/// Creates a routing slip from a ${...} template that resolves to a delimited URI string
/// (a literal like "direct:a,direct:b" works too).
///
public RoutingSlipDefinition(string slipTemplate, string uriDelimiter = DefaultDelimiter, bool ignoreInvalidEndpoints = false)
{
ArgumentException.ThrowIfNullOrWhiteSpace(slipTemplate);
var delimiter = string.IsNullOrEmpty(uriDelimiter) ? DefaultDelimiter : uriDelimiter;
_slipFactory = ex => Split(ExpressionResolver.ProcessTemplate(slipTemplate, ex), delimiter);
_ignoreInvalidEndpoints = ignoreInvalidEndpoints;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
{
var logger = context.GetService()?.CreateLogger();
return new RoutingSlipProcessor(context, _slipFactory, _ignoreInvalidEndpoints, logger);
}
private static IEnumerable Split(string? slip, string delimiter) =>
string.IsNullOrEmpty(slip)
? Array.Empty()
: slip.Split(delimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
}