Class ThreadsProcessor
Threads EIP — Camel-style concurrency stage. Hands each incoming exchange to a bounded pool
of poolSize persistent workers that run the child pipeline (the body), capping the
section's concurrency at poolSize.
Adaptive by exchange pattern (one API, transparent the way Camel's threads() is):
InOnly — fire-and-forget hand-off: the caller returns as soon as the exchange is
accepted, so a strictly serial polling consumer (file / sql / imap / …) can dispatch the next
item while the pool processes the current one — up to poolSize in parallel. This is the
general-purpose alternative to .To("seda://x").ConcurrentConsumers(N), without a named
endpoint. The exchange is cloned (own DI scope), enqueued to the worker pool, and the
worker (started under — a transaction boundary,
like .To("seda://")) owns and disposes the clone.InOut — request/reply: the body runs inline on the SAME exchange under a
gate (≤ poolSize concurrent; the rest wait for a permit).
Nothing is cloned or copied, so In / Out / headers / properties and the reply are
preserved exactly — lossless regardless of whether the route writes its response to
Out or to In (redb.Route's HTTP consumer falls back to In when Out is
unset). This is not a transaction boundary — the ambient TransactionScope flows into
the body, which is correct for request/reply (the caller awaits the result anyway). Exceptions
propagate up to the route's outer OnException wrapper exactly as an un-threaded inline route, so
error handling / Handled() is unchanged.
Backpressure: InOnly waits on the bounded hand-off queue; InOut waits on the gate. Both honour
— bound the wait for a free slot instead of waiting indefinitely
(on timeout, ; for InOut that surfaces to the awaiting caller).
Drain-on-stop: the processor registers itself as an ;
on context stop it stops accepting, completes the queue, awaits the workers (bounded by
) and force-cancels only if that window is exceeded. A straggler exchange
that arrives after the queue is completed is run inline so it is never dropped.
Ordering is not preserved when poolSize > 1 (documented, same as brokers).
public sealed class ThreadsProcessor : IProcessor, IRouteLifecycleListener
Inheritance
Implements
Properties
DrainTimeout
Graceful-drain window on stop before workers are force-cancelled (default 30s).
public TimeSpan DrainTimeout { get; init; }
EnqueueTimeout
Optional cap on how long a caller waits for a free worker slot when the pool + queue are
public TimeSpan? EnqueueTimeout { get; init; }
PoolSize
Number of concurrent workers (the effective max degree of parallelism).
public int PoolSize { get; }
ProcessedCount
Total number of exchanges processed across all workers.
public long ProcessedCount { get; }
Methods
OnContextStopping(IRouteContext, CancellationToken)
Fired before the context begins stopping routes.
public Task OnContextStopping(IRouteContext context, CancellationToken ct)
Process(IExchange, CancellationToken)
Processes the exchange asynchronously.
public Task Process(IExchange exchange, CancellationToken ct = default)
Constructors
ThreadsProcessor(IProcessor, int, int, IRouteContext, ILogger?)
Creates a Threads processor.