Interface IChannel
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
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
ContinuationTimeout
Amount of time protocol operations (e.g.
queue.declare
) are allowed to take before
timing out.
TimeSpan ContinuationTimeout { get; set; }
Property Value
CurrentQueue
The name of the last queue declared on this channel.
string? CurrentQueue { get; }
Property Value
Remarks
DefaultConsumer
Signalled when an unexpected message is delivered.
IAsyncBasicConsumer? DefaultConsumer { get; set; }
Property Value
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
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
Methods
BasicAckAsync(ulong, bool, CancellationToken)
Asynchronously acknknowledges one or more messages.
ValueTask BasicAckAsync(ulong deliveryTag, bool multiple, CancellationToken cancellationToken = default)
Parameters
deliveryTag
ulongThe delivery tag.
multiple
boolAck all messages up to the delivery tag if set to
true
.cancellationToken
CancellationTokenCancellation token for this operation.
Returns
BasicCancelAsync(string, bool, CancellationToken)
Asynchronously cancel a Basic content-class consumer.
Task BasicCancelAsync(string consumerTag, bool noWait = false, CancellationToken cancellationToken = default)
Parameters
consumerTag
stringThe consumer tag.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellation token for this operation.
Returns
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
stringThe queue.
autoAck
boolIf set to
true
, automatically ack messages.consumerTag
stringThe consumer tag.
noLocal
boolIf set to
true
, this consumer will not receive messages published by the same connection.exclusive
boolIf set to
true
, the consumer is exclusive.arguments
IDictionary<string, object>Consumer arguments.
consumer
IAsyncBasicConsumerThe consumer, an instance of IAsyncBasicConsumer
cancellationToken
CancellationTokenCancellation token for this operation.
Returns
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
stringThe queue.
autoAck
boolIf set to
true
, automatically ack the message.cancellationToken
CancellationTokenCancellation token for this operation.
Returns
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
ulongThe delivery tag.
multiple
boolIf set to
true
, nack all messages up to the current tag.requeue
boolIf set to
true
, requeue nack'd messages.cancellationToken
CancellationTokenCancellation token for this operation.
Returns
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
CachedStringThe exchange.
routingKey
CachedStringThe routing key.
mandatory
boolIf set to
true
, the message must route to a queue.basicProperties
TPropertiesThe message properties.
body
ReadOnlyMemory<byte>The message body.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe exchange.
routingKey
stringThe routing key.
mandatory
boolIf set to
true
, the message must route to a queue.basicProperties
TPropertiesThe message properties.
body
ReadOnlyMemory<byte>The message body.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
uintSize of the prefetch in bytes.
prefetchCount
ushortThe prefetch count.
global
boolIf set to
true
, use global prefetch.cancellationToken
CancellationTokenCancellation token for this operation.
Returns
Remarks
See the Consumer Prefetch documentation.
BasicRejectAsync(ulong, bool, CancellationToken)
Reject a delivered message.
ValueTask BasicRejectAsync(ulong deliveryTag, bool requeue, CancellationToken cancellationToken = default)
Parameters
deliveryTag
ulongThe delivery tag.
requeue
boolIf set to
true
, requeue rejected messages.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
CloseAsync(ShutdownEventArgs, bool, CancellationToken)
Asynchronously close this session.
Task CloseAsync(ShutdownEventArgs reason, bool abort, CancellationToken cancellationToken = default)
Parameters
reason
ShutdownEventArgsThe ShutdownEventArgs instance containing the close data.
abort
boolWhether or not the close is an abort (ignoring certain exceptions).
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
CloseAsync(ushort, string, bool, CancellationToken)
Asynchronously close this session.
Task CloseAsync(ushort replyCode, string replyText, bool abort, CancellationToken cancellationToken = default)
Parameters
replyCode
ushortThe reply code to send for closing (See under "Reply Codes" in the AMQP specification).
replyText
stringThe reply text to send for closing.
abort
boolWhether or not the close is an abort (ignoring certain exceptions).
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the queue
cancellationToken
CancellationTokenThe cancellation token.
Returns
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
stringThe name of the destination exchange.
source
stringThe name of the source exchange.
routingKey
stringThe routing key.
arguments
IDictionary<string, object>The binding arguments.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the exchange.
type
stringThe type of the exchange.
durable
boolShould this exchange survive a broker restart?
autoDelete
boolShould this exchange be auto-deleted?
arguments
IDictionary<string, object>The arguments.
passive
boolOptional; Set to
to passively declare the exchange (i.e. check for its existence)true
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the exchange.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the exchange.
ifUnused
boolOnly delete the exchange if it is unused.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the destination exchange.
source
stringThe name of the source exchange.
routingKey
stringThe routing key.
arguments
IDictionary<string, object>The binding arguments.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
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
stringThe name of the queue
cancellationToken
CancellationTokenThe cancellation token.
Returns
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
stringThe queue.
exchange
stringThe exchange.
routingKey
stringThe routing key.
arguments
IDictionary<string, object>The arguments.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the queue. Pass an empty string to make the server generate a name.
durable
boolShould this queue survive a broker restart?
exclusive
boolShould this queue use be limited to its declaring connection? Such a queue will be deleted when its declaring connection closes.
autoDelete
boolShould 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
boolOptional; Set to
to passively declare the queue (i.e. check for its existence)true
noWait
boolOptional; Set to
true
to not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
QueueDeclarePassiveAsync(string, CancellationToken)
Asynchronously declare a queue passively.
Task<QueueDeclareOk> QueueDeclarePassiveAsync(string queue, CancellationToken cancellationToken = default)
Parameters
queue
stringThe name of the queue. Pass an empty string to make the server generate a name.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe name of the queue.
ifUnused
boolOnly delete the queue if it is unused.
ifEmpty
boolOnly delete the queue if it is empty.
noWait
boolIf set to
true
, do not require a response from the server.cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe queue.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
stringThe queue.
exchange
stringThe exchange.
routingKey
stringThe routing key.
arguments
IDictionary<string, object>The arguments.
cancellationToken
CancellationTokenCancellationToken for this operation.
Returns
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
CancellationTokenThe cancellation token.
Returns
TxRollbackAsync(CancellationToken)
Asynchronously roll back this session's active TX transaction.
Task TxRollbackAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
TxSelectAsync(CancellationToken)
Asynchronously enable TX mode for this session.
Task TxSelectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe cancellation token.
Returns
Events
BasicAcksAsync
Signalled when a Basic.Ack command arrives from the broker.
event AsyncEventHandler<BasicAckEventArgs> BasicAcksAsync
Event Type
BasicNacksAsync
Signalled when a Basic.Nack command arrives from the broker.
event AsyncEventHandler<BasicNackEventArgs> BasicNacksAsync
Event Type
BasicReturnAsync
Signalled when a Basic.Return command arrives from the broker.
event AsyncEventHandler<BasicReturnEventArgs> BasicReturnAsync
Event Type
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
ChannelShutdownAsync
Notifies the destruction of the channel.
event AsyncEventHandler<ShutdownEventArgs> ChannelShutdownAsync
Event Type
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