Path: redb-route/redb.Route/Processors/InterceptSendProcessor.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/InterceptSendProcessor.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Processors;
///
/// Wraps a To / ToD: when the target URI matches the mask, publishes it in the exchange property
/// (Camel's CamelToEndpoint), runs the intercept steps, and
/// then sends to the original endpoint — unless the intercept asked to skip it (dry run, test double)
/// or stopped the exchange. A non-matching URI (dynamic targets) is sent untouched.
///
internal sealed class InterceptSendProcessor : IProcessor
{
private readonly IProcessor _intercept;
private readonly IPredicate? _condition;
private readonly bool _skipOriginal;
private readonly string _uriPattern;
private readonly Func _targetUri;
private readonly IProcessor _send;
private readonly DynamicEndpointResolver? _resolver;
/// For a dynamic target: the node's own resolver, so the URI resolved here is the one the send uses (evaluated once per message).
public InterceptSendProcessor(IProcessor intercept, IPredicate? condition, bool skipOriginal, string uriPattern,
Func targetUri, IProcessor send, DynamicEndpointResolver? resolver = null)
{
_intercept = intercept ?? throw new ArgumentNullException(nameof(intercept));
_condition = condition;
_skipOriginal = skipOriginal;
_uriPattern = uriPattern ?? throw new ArgumentNullException(nameof(uriPattern));
_targetUri = targetUri ?? throw new ArgumentNullException(nameof(targetUri));
_send = send ?? throw new ArgumentNullException(nameof(send));
_resolver = resolver;
}
public async Task Process(IExchange exchange, CancellationToken ct = default)
{
var parked = false;
var uri = _resolver is null ? _targetUri(exchange) : _resolver.ResolveAndPark(exchange, out parked);
try
{
if (!UriMask.IsMatch(_uriPattern, uri))
{
await _send.Process(exchange, ct).ConfigureAwait(false);
return;
}
// Exchange properties reach logs, traces and the dashboard: publish the target without its secrets.
exchange.Properties[ExchangePropertyKeys.ToEndpoint] = EndpointUri.Sanitize(uri);
if (_condition is not null && !await _condition.MatchesAsync(exchange).ConfigureAwait(false))
{
await _send.Process(exchange, ct).ConfigureAwait(false);
return;
}
await _intercept.Process(exchange, ct).ConfigureAwait(false);
if (exchange.IsStopped || _skipOriginal)
return;
await _send.Process(exchange, ct).ConfigureAwait(false);
}
finally
{
if (parked) _resolver!.Unpark(exchange);
}
}
}