Table of Contents

Interface IChannel

Namespace
RabbitMQ.Client
Assembly
RabbitMQ.Client.dll

Common AMQP model, spanning the union of the functionality offered by versions 0-8, 0-8qpid, 0-9 and 0-9-1 of AMQP.

public interface IChannel : IAsyncDisposable, IDisposable
Inherited Members
Extension Methods

Remarks

Extends the IDisposable interface and the IAsyncDisposable interface, so that the "using" statement can be used to scope the lifetime of a channel when appropriate.

Properties

ChannelNumber

Channel number, unique per connections.

int ChannelNumber { get; }

Property Value

int

CloseReason

Returns null if the session is still in a state where it can be used, or the cause of its closure otherwise.

ShutdownEventArgs? CloseReason { get; }

Property Value

ShutdownEventArgs

ContinuationTimeout

Amount of time protocol operations (e.g.

queue.declare
) are allowed to take before timing out.
TimeSpan ContinuationTimeout { get; set; }

Property Value

TimeSpan

CurrentQueue

The name of the last queue declared on this channel.

string? CurrentQueue { get; }

Property Value

string

Remarks

DefaultConsumer

Signalled when an unexpected message is delivered.

IAsyncBasicConsumer? DefaultConsumer { get; set; }

Property Value

IAsyncBasicConsumer

Remarks

Under certain circumstances it is possible for a channel to receive a message delivery which does not match any consumer which is currently set up via basicConsume(). This will occur after the following sequence of events:

ctag = basicConsume(queue, consumer); // i.e. with explicit acks // some deliveries take place but are not acked basicCancel(ctag); basicRecover(false);

Since requeue is specified to be false in the basicRecover, the spec states that the message must be redelivered to "the original recipient"

  • i.e. the same channel / consumer-tag. But the consumer is no longer active.

In these circumstances, you can register a default consumer to handle such deliveries. If no default consumer is registered an InvalidOperationException will be thrown when such a delivery arrives.

Most people will not need to use this.

IsClosed

Returns true if the channel is no longer in a state where it can be used.

bool IsClosed { get; }

Property Value

bool

IsOpen

Returns true if the channel is still in a state where it can be used. Identical to checking if CloseReason equals null.

bool IsOpen { get; }

Property Value

bool

Methods

BasicAckAsync(ulong, bool, CancellationToken)

Asynchronously acknknowledges one or more messages.

ValueTask BasicAckAsync(ulong deliveryTag, bool multiple, CancellationToken cancellationToken = default)

Parameters

deliveryTag ulong

The delivery tag.

multiple bool

Ack all messages up to the delivery tag if set to true.

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

ValueTask

BasicCancelAsync(string, bool, CancellationToken)

Asynchronously cancel a Basic content-class consumer.

Task BasicCancelAsync(string consumerTag, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

consumerTag string

The consumer tag.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

Task

BasicConsumeAsync(string, bool, string, bool, bool, IDictionary<string, object?>?, IAsyncBasicConsumer, CancellationToken)

Asynchronously start a Basic content-class consumer.

Task<string> BasicConsumeAsync(string queue, bool autoAck, string consumerTag, bool noLocal, bool exclusive, IDictionary<string, object?>? arguments, IAsyncBasicConsumer consumer, CancellationToken cancellationToken = default)

Parameters

queue string

The queue.

autoAck bool

If set to true, automatically ack messages.

consumerTag string

The consumer tag.

noLocal bool

If set to true, this consumer will not receive messages published by the same connection.

exclusive bool

If set to true, the consumer is exclusive.

arguments IDictionary<string, object>

Consumer arguments.

consumer IAsyncBasicConsumer

The consumer, an instance of IAsyncBasicConsumer

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

Task<string>

BasicGetAsync(string, bool, CancellationToken)

Asynchronously retrieve an individual message, if one is available; returns null if the server answers that no messages are currently available. See also BasicAckAsync(ulong, bool, CancellationToken).

Task<BasicGetResult?> BasicGetAsync(string queue, bool autoAck, CancellationToken cancellationToken = default)

Parameters

queue string

The queue.

autoAck bool

If set to true, automatically ack the message.

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

Task<BasicGetResult>

BasicGetResult

BasicNackAsync(ulong, bool, bool, CancellationToken)

Asynchronously nack one or more delivered message(s).

ValueTask BasicNackAsync(ulong deliveryTag, bool multiple, bool requeue, CancellationToken cancellationToken = default)

Parameters

deliveryTag ulong

The delivery tag.

multiple bool

If set to true, nack all messages up to the current tag.

requeue bool

If set to true, requeue nack'd messages.

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

ValueTask

BasicPublishAsync<TProperties>(CachedString, CachedString, bool, TProperties, ReadOnlyMemory<byte>, CancellationToken)

Asynchronously publishes a message.

ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body, CancellationToken cancellationToken = default) where TProperties : IReadOnlyBasicProperties, IAmqpHeader

Parameters

exchange CachedString

The exchange.

routingKey CachedString

The routing key.

mandatory bool

If set to true, the message must route to a queue.

basicProperties TProperties

The message properties.

body ReadOnlyMemory<byte>

The message body.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

ValueTask

Type Parameters

TProperties

Remarks

Routing key must be shorter than 255 bytes. Throws PublishException if a nack or basic.return is returned for the message.

BasicPublishAsync<TProperties>(string, string, bool, TProperties, ReadOnlyMemory<byte>, CancellationToken)

Asynchronously publishes a message.

ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body, CancellationToken cancellationToken = default) where TProperties : IReadOnlyBasicProperties, IAmqpHeader

Parameters

exchange string

The exchange.

routingKey string

The routing key.

mandatory bool

If set to true, the message must route to a queue.

basicProperties TProperties

The message properties.

body ReadOnlyMemory<byte>

The message body.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

ValueTask

Type Parameters

TProperties

Remarks

Routing key must be shorter than 255 bytes. Throws PublishException if a nack or basic.return is returned for the message.

BasicQosAsync(uint, ushort, bool, CancellationToken)

Configures QoS parameters of the Basic content-class.

Task BasicQosAsync(uint prefetchSize, ushort prefetchCount, bool global, CancellationToken cancellationToken = default)

Parameters

prefetchSize uint

Size of the prefetch in bytes.

prefetchCount ushort

The prefetch count.

global bool

If set to true, use global prefetch.

cancellationToken CancellationToken

Cancellation token for this operation.

Returns

Task

Remarks

BasicRejectAsync(ulong, bool, CancellationToken)

Reject a delivered message.

ValueTask BasicRejectAsync(ulong deliveryTag, bool requeue, CancellationToken cancellationToken = default)

Parameters

deliveryTag ulong

The delivery tag.

requeue bool

If set to true, requeue rejected messages.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

ValueTask

CloseAsync(ShutdownEventArgs, bool, CancellationToken)

Asynchronously close this session.

Task CloseAsync(ShutdownEventArgs reason, bool abort, CancellationToken cancellationToken = default)

Parameters

reason ShutdownEventArgs

The ShutdownEventArgs instance containing the close data.

abort bool

Whether or not the close is an abort (ignoring certain exceptions).

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

CloseAsync(ushort, string, bool, CancellationToken)

Asynchronously close this session.

Task CloseAsync(ushort replyCode, string replyText, bool abort, CancellationToken cancellationToken = default)

Parameters

replyCode ushort

The reply code to send for closing (See under "Reply Codes" in the AMQP specification).

replyText string

The reply text to send for closing.

abort bool

Whether or not the close is an abort (ignoring certain exceptions).

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

ConsumerCountAsync(string, CancellationToken)

Returns the number of consumers on a queue. This method assumes the queue exists. If it doesn't, an exception will be closed with an exception.

Task<uint> ConsumerCountAsync(string queue, CancellationToken cancellationToken = default)

Parameters

queue string

The name of the queue

cancellationToken CancellationToken

The cancellation token.

Returns

Task<uint>

ExchangeBindAsync(string, string, string, IDictionary<string, object?>?, bool, CancellationToken)

Asynchronously binds an exchange to an exchange.

Task ExchangeBindAsync(string destination, string source, string routingKey, IDictionary<string, object?>? arguments = null, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

destination string

The name of the destination exchange.

source string

The name of the source exchange.

routingKey string

The routing key.

arguments IDictionary<string, object>

The binding arguments.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

Routing key must be shorter than 255 bytes.

ExchangeDeclareAsync(string, string, bool, bool, IDictionary<string, object?>?, bool, bool, CancellationToken)

Asynchronously declare an exchange.

Task ExchangeDeclareAsync(string exchange, string type, bool durable, bool autoDelete, IDictionary<string, object?>? arguments = null, bool passive = false, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

exchange string

The name of the exchange.

type string

The type of the exchange.

durable bool

Should this exchange survive a broker restart?

autoDelete bool

Should this exchange be auto-deleted?

arguments IDictionary<string, object>

The arguments.

passive bool

Optional; Set to

true
to passively declare the exchange (i.e. check for its existence)
noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

The exchange is declared non-internal.

ExchangeDeclarePassiveAsync(string, CancellationToken)

Asynchronously do a passive exchange declaration.

Task ExchangeDeclarePassiveAsync(string exchange, CancellationToken cancellationToken = default)

Parameters

exchange string

The name of the exchange.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

This method performs a "passive declare" on an exchange, which checks whether an exchange exists. It will do nothing if the exchange already exists and result in a channel-level protocol exception (channel closure) if not.

ExchangeDeleteAsync(string, bool, bool, CancellationToken)

Asynchronously delete an exchange.

Task ExchangeDeleteAsync(string exchange, bool ifUnused = false, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

exchange string

The name of the exchange.

ifUnused bool

Only delete the exchange if it is unused.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

ExchangeUnbindAsync(string, string, string, IDictionary<string, object?>?, bool, CancellationToken)

Asynchronously unbind an exchange from an exchange.

Task ExchangeUnbindAsync(string destination, string source, string routingKey, IDictionary<string, object?>? arguments = null, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

destination string

The name of the destination exchange.

source string

The name of the source exchange.

routingKey string

The routing key.

arguments IDictionary<string, object>

The binding arguments.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

Routing key must be shorter than 255 bytes.

GetNextPublishSequenceNumberAsync(CancellationToken)

When in confirm mode, return the sequence number of the next message to be published.

ValueTask<ulong> GetNextPublishSequenceNumberAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<ulong>

MessageCountAsync(string, CancellationToken)

Returns the number of messages in a queue ready to be delivered to consumers. This method assumes the queue exists. If it doesn't, an exception will be closed with an exception.

Task<uint> MessageCountAsync(string queue, CancellationToken cancellationToken = default)

Parameters

queue string

The name of the queue

cancellationToken CancellationToken

The cancellation token.

Returns

Task<uint>

QueueBindAsync(string, string, string, IDictionary<string, object?>?, bool, CancellationToken)

Asynchronously bind a queue to an exchange.

Task QueueBindAsync(string queue, string exchange, string routingKey, IDictionary<string, object?>? arguments = null, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

queue string

The queue.

exchange string

The exchange.

routingKey string

The routing key.

arguments IDictionary<string, object>

The arguments.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

Routing key must be shorter than 255 bytes.

QueueDeclareAsync(string, bool, bool, bool, IDictionary<string, object?>?, bool, bool, CancellationToken)

Asynchronously declares a queue. See the Queues guide to learn more.

Task<QueueDeclareOk> QueueDeclareAsync(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object?>? arguments = null, bool passive = false, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

queue string

The name of the queue. Pass an empty string to make the server generate a name.

durable bool

Should this queue survive a broker restart?

exclusive bool

Should this queue use be limited to its declaring connection? Such a queue will be deleted when its declaring connection closes.

autoDelete bool

Should this queue be auto-deleted when its last consumer (if any) unsubscribes?

arguments IDictionary<string, object>

Optional; additional queue arguments, e.g. "x-queue-type"

passive bool

Optional; Set to

true
to passively declare the queue (i.e. check for its existence)
noWait bool

Optional; Set to true to not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task<QueueDeclareOk>

QueueDeclarePassiveAsync(string, CancellationToken)

Asynchronously declare a queue passively.

Task<QueueDeclareOk> QueueDeclarePassiveAsync(string queue, CancellationToken cancellationToken = default)

Parameters

queue string

The name of the queue. Pass an empty string to make the server generate a name.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task<QueueDeclareOk>

Remarks

The queue is declared passive, non-durable, non-exclusive, and non-autodelete, with no arguments. The queue is declared passively; i.e. only check if it exists.

QueueDeleteAsync(string, bool, bool, bool, CancellationToken)

Asynchronously deletes a queue. See the Queues guide to learn more.

Task<uint> QueueDeleteAsync(string queue, bool ifUnused, bool ifEmpty, bool noWait = false, CancellationToken cancellationToken = default)

Parameters

queue string

The name of the queue.

ifUnused bool

Only delete the queue if it is unused.

ifEmpty bool

Only delete the queue if it is empty.

noWait bool

If set to true, do not require a response from the server.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task<uint>

Remarks

Returns the number of messages purged during queue deletion.

QueuePurgeAsync(string, CancellationToken)

Asynchronously purge a queue of messages.

Task<uint> QueuePurgeAsync(string queue, CancellationToken cancellationToken = default)

Parameters

queue string

The queue.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task<uint>

Returns the number of messages purged.

QueueUnbindAsync(string, string, string, IDictionary<string, object?>?, CancellationToken)

Asynchronously unbind a queue from an exchange.

Task QueueUnbindAsync(string queue, string exchange, string routingKey, IDictionary<string, object?>? arguments = null, CancellationToken cancellationToken = default)

Parameters

queue string

The queue.

exchange string

The exchange.

routingKey string

The routing key.

arguments IDictionary<string, object>

The arguments.

cancellationToken CancellationToken

CancellationToken for this operation.

Returns

Task

Remarks

Routing key must be shorter than 255 bytes.

TxCommitAsync(CancellationToken)

Asynchronously commit this session's active TX transaction.

Task TxCommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task

TxRollbackAsync(CancellationToken)

Asynchronously roll back this session's active TX transaction.

Task TxRollbackAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task

TxSelectAsync(CancellationToken)

Asynchronously enable TX mode for this session.

Task TxSelectAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task

Events

BasicAcksAsync

Signalled when a Basic.Ack command arrives from the broker.

event AsyncEventHandler<BasicAckEventArgs> BasicAcksAsync

Event Type

AsyncEventHandler<BasicAckEventArgs>

BasicNacksAsync

Signalled when a Basic.Nack command arrives from the broker.

event AsyncEventHandler<BasicNackEventArgs> BasicNacksAsync

Event Type

AsyncEventHandler<BasicNackEventArgs>

BasicReturnAsync

Signalled when a Basic.Return command arrives from the broker.

event AsyncEventHandler<BasicReturnEventArgs> BasicReturnAsync

Event Type

AsyncEventHandler<BasicReturnEventArgs>

CallbackExceptionAsync

Signalled when an exception occurs in a callback invoked by the channel.

Examples of cases where this event will be signalled include exceptions thrown in IAsyncBasicConsumer methods, or exceptions thrown in ChannelShutdownAsync delegates etc.

event AsyncEventHandler<CallbackExceptionEventArgs> CallbackExceptionAsync

Event Type

AsyncEventHandler<CallbackExceptionEventArgs>

ChannelShutdownAsync

Notifies the destruction of the channel.

event AsyncEventHandler<ShutdownEventArgs> ChannelShutdownAsync

Event Type

AsyncEventHandler<ShutdownEventArgs>

Remarks

If the channel is already destroyed at the time an event handler is added to this event, the event handler will be fired immediately.

FlowControlAsync

event AsyncEventHandler<FlowControlEventArgs> FlowControlAsync

Event Type

AsyncEventHandler<FlowControlEventArgs>