Class DrainableConsumer
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
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; }
Methods
AwaitRunTask()
Awaits the run task. Override for consumers with multiple workers (e.g. Task.WhenAll).
protected virtual Task AwaitRunTask()
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)
Constructors
DrainableConsumer(IProcessor)
Creates a drainable consumer.