Table of Contents

Class AsyncDefaultBasicConsumer

Namespace
RabbitMQ.Client
Assembly
RabbitMQ.Client.dll
public class AsyncDefaultBasicConsumer : IAsyncBasicConsumer
Inheritance
AsyncDefaultBasicConsumer
Implements
Derived
Inherited Members

Constructors

AsyncDefaultBasicConsumer(IChannel)

Constructor which sets the Channel property to the given value.

public AsyncDefaultBasicConsumer(IChannel channel)

Parameters

channel IChannel

Common AMQP channel.

Properties

Channel

Retrieve the IChannel this consumer is associated with, for use in acknowledging received messages, for instance.

public IChannel Channel { get; }

Property Value

IChannel

ConsumerTags

Retrieve the consumer tags this consumer is registered as; to be used when discussing this consumer with the server, for instance with BasicCancelAsync(string, bool, CancellationToken).

public string[] ConsumerTags { get; }

Property Value

string[]

IsRunning

Returns true while the consumer is registered and expecting deliveries from the broker.

public bool IsRunning { get; }

Property Value

bool

ShutdownReason

If our IChannel shuts down, this property will contain a description of the reason for the shutdown. Otherwise it will contain null. See ShutdownEventArgs.

public ShutdownEventArgs? ShutdownReason { get; }

Property Value

ShutdownEventArgs

Methods

HandleBasicCancelAsync(string, CancellationToken)

Called when the consumer is cancelled for reasons other than by a basicCancel: e.g. the queue has been deleted (either by this channel or by any other channel). See HandleBasicCancelOkAsync(string, CancellationToken) for notification of consumer cancellation due to basicCancel

public virtual Task HandleBasicCancelAsync(string consumerTag, CancellationToken cancellationToken = default)

Parameters

consumerTag string

Consumer tag this consumer is registered.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

HandleBasicCancelOkAsync(string, CancellationToken)

Called upon successful deregistration of the consumer from the broker.

public virtual Task HandleBasicCancelOkAsync(string consumerTag, CancellationToken cancellationToken = default)

Parameters

consumerTag string

Consumer tag this consumer is registered.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

HandleBasicConsumeOkAsync(string, CancellationToken)

Called upon successful registration of the consumer with the broker.

public virtual Task HandleBasicConsumeOkAsync(string consumerTag, CancellationToken cancellationToken = default)

Parameters

consumerTag string

Consumer tag this consumer is registered.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

HandleBasicDeliverAsync(string, ulong, bool, string, string, IReadOnlyBasicProperties, ReadOnlyMemory<byte>, CancellationToken)

Called each time a message is delivered for this consumer.

public virtual Task HandleBasicDeliverAsync(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body, CancellationToken cancellationToken = default)

Parameters

consumerTag string
deliveryTag ulong
redelivered bool
exchange string
routingKey string
properties IReadOnlyBasicProperties
body ReadOnlyMemory<byte>
cancellationToken CancellationToken

Returns

Task

Remarks

This is a no-op implementation. It will not acknowledge deliveries via BasicAckAsync(ulong, bool, CancellationToken) if consuming in automatic acknowledgement mode. Subclasses must copy or fully use delivery body before returning. Accessing the body at a later point is unsafe as its memory can be already released.

HandleChannelShutdownAsync(object, ShutdownEventArgs)

Called when the channel (channel) this consumer was registered on terminates.

public virtual Task HandleChannelShutdownAsync(object channel, ShutdownEventArgs reason)

Parameters

channel object

A channel this consumer was registered on.

reason ShutdownEventArgs

Shutdown context.

Returns

Task

OnCancelAsync(string[], CancellationToken)

Default implementation - overridable in subclasses.

protected virtual Task OnCancelAsync(string[] consumerTags, CancellationToken cancellationToken = default)

Parameters

consumerTags string[]

The set of consumer tags that were cancelled

cancellationToken CancellationToken

The cancellation token.

Returns

Task

Remarks

This default implementation simply sets the IsRunning property to false, and takes no further action.