Class PushConsumer

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

Base class for consumers whose client library calls a handler for every message (RabbitMQ
AsyncEventingBasicConsumer, MQTT, a service bus processor): the counterpart of ,
which runs its own receive loop. The base keeps the order of a graceful stop, so a connector does not repeat it:
new messages are refused once a stop begins, the messages in work drain within , then their
processing is cancelled, and only then is the subscription released.

The connector gives three steps: (open and subscribe),
(cancel the subscription so nothing new arrives) and (release what Subscribe opened).
Its message handler calls and settles the message by the : the
base never acknowledges, the rules of that differ per broker.


A subscription the broker ends while the route runs (a closed channel, a dropped link) is reported to a
(), and brings it
back on the supervisor's schedule while the endpoint's health says so.

public abstract class PushConsumer : IConsumer

Inheritance

Object→PushConsumer

Implements

Derived

Properties

ConsumerEndpoint

The endpoint this consumer is attached to.

protected abstract IEndpoint ConsumerEndpoint { get; }

ConsumerName

Display name for logging (rabbitmq:orders).

protected abstract string ConsumerName { get; }

DrainTimeout

How long a stop waits for the messages in work before it cancels their processing (default 30 s).

protected TimeSpan DrainTimeout { get; set; }

Endpoint

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

public IEndpoint Endpoint { get; }

InflightCount

Messages in work now.

protected int InflightCount { get; }

IsStopping

Set once a stop begins: from then on a cancelled subscription or a closed channel is the stop's, not news.

protected bool IsStopping { get; }

Logger

Logger resolved from the component.

protected ILogger? Logger { get; }

ProcessingToken

The processing token of the messages in work; cancelled when the drain window of a stop runs out.

protected CancellationToken ProcessingToken { get; }

Processor

The route the messages run through.

protected IProcessor Processor { get; }

StopToken

Cancelled when a stop begins, before the drain; a pause or a wait of the connector's own ends with it.

protected CancellationToken StopToken { get; }

Methods

DispatchAsync(Func<IExchange>, TransportSpan, PushRetry?, Func<IExchange, CancellationToken, Task>?)

Runs one message through the route and says what became of it; the connector settles it by the outcome. Refused

protected Task<PushDispatch> DispatchAsync(Func<IExchange> createExchange, TransportSpan span, PushRetry? retry = null, Func<IExchange, CancellationToken, Task>? afterRoute = null)

IsOwnStop(Exception, CancellationToken)

A cancellation the consumer's own stop caused; any other one, a timeout inside the route included, is a failure.

protected bool IsOwnStop(Exception exception, CancellationToken processingToken)

ResubscribeAsync(ConnectionSupervisor, Func<CancellationToken, Task>)

Brings a lost subscription back: runs resubscribe on the supervisor's schedule

protected Task<bool> ResubscribeAsync(ConnectionSupervisor supervisor, Func<CancellationToken, Task> resubscribe)

Start(CancellationToken)

Starts consuming messages.

public Task Start(CancellationToken ct = default)

Stop(CancellationToken)

Stops consuming messages.

public Task Stop(CancellationToken ct = default)

StopAcceptingAsync(CancellationToken)

Cancels the subscription so that no new message arrives (a broker-side cancel); errors are logged.

protected abstract Task StopAcceptingAsync(CancellationToken ct)

SubscribeAsync(CancellationToken)

Opens what the subscription needs and subscribes; a failure fails the start.

protected abstract Task SubscribeAsync(CancellationToken ct)

SuperviseConnection(string)

Creates a supervisor for one subscription of this consumer and registers it with the endpoint, whose health then

protected ConnectionSupervisor SuperviseConnection(string name)

TrackInflight()

Counts one unit of work the connector runs itself (a batch) as in work, so a stop's drain waits for it; dispose

protected PushConsumer.InflightScope TrackInflight()

UnsubscribeAsync(CancellationToken)

Releases what opened; runs after the drain.

protected abstract Task UnsubscribeAsync(CancellationToken ct)

Constructors

PushConsumer(IProcessor, int?)

Creates a push consumer.