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
deliveryTagulongThe delivery tag.
multipleboolAck all messages up to the delivery tag if set to
true.cancellationTokenCancellationTokenCancellation 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
consumerTagstringThe consumer tag.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellation 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
queuestringThe queue.
autoAckboolIf set to
true, automatically ack messages.consumerTagstringThe consumer tag.
noLocalboolIf set to
true, this consumer will not receive messages published by the same connection.exclusiveboolIf set to
true, the consumer is exclusive.argumentsIDictionary<string, object>Consumer arguments.
consumerIAsyncBasicConsumerThe consumer, an instance of IAsyncBasicConsumer
cancellationTokenCancellationTokenCancellation 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
queuestringThe queue.
autoAckboolIf set to
true, automatically ack the message.cancellationTokenCancellationTokenCancellation 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
deliveryTagulongThe delivery tag.
multipleboolIf set to
true, nack all messages up to the current tag.requeueboolIf set to
true, requeue nack'd messages.cancellationTokenCancellationTokenCancellation 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
exchangeCachedStringThe exchange.
routingKeyCachedStringThe routing key.
mandatoryboolIf set to
true, the message must route to a queue.basicPropertiesTPropertiesThe message properties.
bodyReadOnlyMemory<byte>The message body.
cancellationTokenCancellationTokenCancellationToken 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
exchangestringThe exchange.
routingKeystringThe routing key.
mandatoryboolIf set to
true, the message must route to a queue.basicPropertiesTPropertiesThe message properties.
bodyReadOnlyMemory<byte>The message body.
cancellationTokenCancellationTokenCancellationToken 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
prefetchSizeuintSize of the prefetch in bytes.
prefetchCountushortThe prefetch count.
globalboolIf set to
true, use global prefetch.cancellationTokenCancellationTokenCancellation 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
deliveryTagulongThe delivery tag.
requeueboolIf set to
true, requeue rejected messages.cancellationTokenCancellationTokenCancellationToken for this operation.
Returns
CloseAsync(ShutdownEventArgs, bool, CancellationToken)
Asynchronously close this session.
Task CloseAsync(ShutdownEventArgs reason, bool abort, CancellationToken cancellationToken = default)
Parameters
reasonShutdownEventArgsThe ShutdownEventArgs instance containing the close data.
abortboolWhether or not the close is an abort (ignoring certain exceptions).
cancellationTokenCancellationTokenCancellationToken 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
replyCodeushortThe reply code to send for closing (See under "Reply Codes" in the AMQP specification).
replyTextstringThe reply text to send for closing.
abortboolWhether or not the close is an abort (ignoring certain exceptions).
cancellationTokenCancellationTokenCancellationToken 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
queuestringThe name of the queue
cancellationTokenCancellationTokenThe 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
destinationstringThe name of the destination exchange.
sourcestringThe name of the source exchange.
routingKeystringThe routing key.
argumentsIDictionary<string, object>The binding arguments.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
exchangestringThe name of the exchange.
typestringThe type of the exchange.
durableboolShould this exchange survive a broker restart?
autoDeleteboolShould this exchange be auto-deleted?
argumentsIDictionary<string, object>The arguments.
passiveboolOptional; Set to
to passively declare the exchange (i.e. check for its existence)truenoWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
exchangestringThe name of the exchange.
cancellationTokenCancellationTokenCancellationToken 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
exchangestringThe name of the exchange.
ifUnusedboolOnly delete the exchange if it is unused.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
destinationstringThe name of the destination exchange.
sourcestringThe name of the source exchange.
routingKeystringThe routing key.
argumentsIDictionary<string, object>The binding arguments.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
cancellationTokenCancellationToken
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
queuestringThe name of the queue
cancellationTokenCancellationTokenThe 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
queuestringThe queue.
exchangestringThe exchange.
routingKeystringThe routing key.
argumentsIDictionary<string, object>The arguments.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
queuestringThe name of the queue. Pass an empty string to make the server generate a name.
durableboolShould this queue survive a broker restart?
exclusiveboolShould this queue use be limited to its declaring connection? Such a queue will be deleted when its declaring connection closes.
autoDeleteboolShould this queue be auto-deleted when its last consumer (if any) unsubscribes?
argumentsIDictionary<string, object>Optional; additional queue arguments, e.g. "x-queue-type"
passiveboolOptional; Set to
to passively declare the queue (i.e. check for its existence)truenoWaitboolOptional; Set to
trueto not require a response from the server.cancellationTokenCancellationTokenCancellationToken for this operation.
Returns
QueueDeclarePassiveAsync(string, CancellationToken)
Asynchronously declare a queue passively.
Task<QueueDeclareOk> QueueDeclarePassiveAsync(string queue, CancellationToken cancellationToken = default)
Parameters
queuestringThe name of the queue. Pass an empty string to make the server generate a name.
cancellationTokenCancellationTokenCancellationToken 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
queuestringThe name of the queue.
ifUnusedboolOnly delete the queue if it is unused.
ifEmptyboolOnly delete the queue if it is empty.
noWaitboolIf set to
true, do not require a response from the server.cancellationTokenCancellationTokenCancellationToken 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
queuestringThe queue.
cancellationTokenCancellationTokenCancellationToken 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
queuestringThe queue.
exchangestringThe exchange.
routingKeystringThe routing key.
argumentsIDictionary<string, object>The arguments.
cancellationTokenCancellationTokenCancellationToken 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
cancellationTokenCancellationTokenThe cancellation token.
Returns
TxRollbackAsync(CancellationToken)
Asynchronously roll back this session's active TX transaction.
Task TxRollbackAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.
Returns
TxSelectAsync(CancellationToken)
Asynchronously enable TX mode for this session.
Task TxSelectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe 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