Class DrainableConsumer

Namespace: redb.Route.Core
Assembly: redb.Route.dll

Base class for consumers with Two-CTS graceful shutdown.
Handles: CTS lifecycle, inflight tracking, drain-on-stop, force-cancel.
Subclasses only implement and optionally override hooks.

public abstract class DrainableConsumer : IConsumer

Inheritance

Object→DrainableConsumer

Implements

Derived

Properties

ConsumerEndpoint

The endpoint this consumer is attached to.

protected abstract IEndpoint ConsumerEndpoint { get; }

ConsumerName

Display name for logging (e.g. "kafka:orders", "file:/tmp/in").

protected abstract string ConsumerName { get; }

Endpoint

The endpoint this consumer is attached to (for diagnostics/logging).

public IEndpoint Endpoint { get; }

Logger

Logger resolved from the component.

protected ILogger? Logger { get; }

Processor

The processor to execute on each exchange.

protected IProcessor Processor { get; }

Methods

AwaitRunTask()

Awaits the run task. Override for consumers with multiple workers (e.g. Task.WhenAll).

protected virtual Task AwaitRunTask()

DecrementInflight()

Decrements the inflight counter.

protected void DecrementInflight()

IncrementInflight()

Increments the inflight counter. Must be paired with .

protected void IncrementInflight()

OnStarting(CancellationToken)

Called during Start() before RunAsync. Override for async setup (topology, subscriptions).

protected virtual Task OnStarting(CancellationToken ct)

OnStopAccepting()

Called at the beginning of Stop() before poll cancel. Override for protocol-level unsubscribe.

protected virtual Task OnStopAccepting()

OnStopped()

Called at the end of Stop() after CTS disposal. Override for resource cleanup.

protected virtual Task OnStopped()

ProcessWithTracking(IExchange, CancellationToken)

Processes an exchange with automatic inflight count tracking.

protected Task ProcessWithTracking(IExchange exchange, CancellationToken processingCt)

ProcessWithTracking(IExchange, TransportSpan, CancellationToken)

inside the receive span of the exchange, opened by

protected Task ProcessWithTracking(IExchange exchange, TransportSpan span, CancellationToken processingCt)

RunAsync(CancellationToken, CancellationToken)

Main consumer loop. Receives pollCt (stop accepting new work)

protected abstract Task RunAsync(CancellationToken pollCt, CancellationToken processingCt)

Start(CancellationToken)

Starts consuming messages.

public Task Start(CancellationToken ct = default)

Stop(CancellationToken)

Stops consuming messages.

public Task Stop(CancellationToken ct = default)

Constructors

DrainableConsumer(IProcessor)

Creates a drainable consumer.