Table of Contents

Interface IModel

Namespace
RabbitMQ.Client
Assembly
Apigen.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 IModel : IDisposable
Inherited Members

Remarks

Extends the IDisposable 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

 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.
IBasicConsumer DefaultConsumer { get; set; }

Property Value

IBasicConsumer

IsClosed

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

bool IsClosed { get; }

Property Value

bool

IsOpen

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

bool IsOpen { get; }

Property Value

bool

NextPublishSeqNo

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

ulong NextPublishSeqNo { get; }

Property Value

ulong

Methods

Abort()

Abort this session.

void Abort()

Remarks

If the session is already closed (or closing), then this method does nothing but wait for the in-progress close operation to complete. This method will not return to the caller until the shutdown is complete. In comparison to normal Close() method, Abort() will not throw Exceptions.AlreadyClosedException or IOException or any other Exception during closing model.

Abort(ushort, string)

Abort this session.

void Abort(ushort replyCode, string replyText)

Parameters

replyCode ushort
replyText string

Remarks

The method behaves in the same way as Abort(), with the only difference that the model is closed with the given model close code and message.

The close code (See under "Reply Codes" in the AMQP specification)

A message indicating the reason for closing the model

BasicAck(ulong, bool)

Acknowledge one or more delivered message(s).

void BasicAck(ulong deliveryTag, bool multiple)

Parameters

deliveryTag ulong
multiple bool

BasicCancel(string)

Delete a Basic content-class consumer.

void BasicCancel(string consumerTag)

Parameters

consumerTag string

BasicCancelNoWait(string)

Same as BasicCancel but sets nowait to true and returns void (as there will be no response from the server).

void BasicCancelNoWait(string consumerTag)

Parameters

consumerTag string

BasicConsume(string, bool, string, bool, bool, IDictionary<string, object>, IBasicConsumer)

Start a Basic content-class consumer.

string BasicConsume(string queue, bool autoAck, string consumerTag, bool noLocal, bool exclusive, IDictionary<string, object> arguments, IBasicConsumer consumer)

Parameters

queue string
autoAck bool
consumerTag string
noLocal bool
exclusive bool
arguments IDictionary<string, object>
consumer IBasicConsumer

Returns

string

BasicGet(string, bool)

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

BasicGetResult BasicGet(string queue, bool autoAck)

Parameters

queue string
autoAck bool

Returns

BasicGetResult

BasicNack(ulong, bool, bool)

Reject one or more delivered message(s).

void BasicNack(ulong deliveryTag, bool multiple, bool requeue)

Parameters

deliveryTag ulong
multiple bool
requeue bool

BasicPublish(string, string, bool, IBasicProperties, ReadOnlyMemory<byte>)

Publishes a message.

void BasicPublish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory<byte> body)

Parameters

exchange string
routingKey string
mandatory bool
basicProperties IBasicProperties
body ReadOnlyMemory<byte>

Remarks

Routing key must be shorter than 255 bytes.

BasicQos(uint, ushort, bool)

Configures QoS parameters of the Basic content-class.

void BasicQos(uint prefetchSize, ushort prefetchCount, bool global)

Parameters

prefetchSize uint
prefetchCount ushort
global bool

BasicRecover(bool)

Indicates that a consumer has recovered. Deprecated. Should not be used.

void BasicRecover(bool requeue)

Parameters

requeue bool

BasicRecoverAsync(bool)

Indicates that a consumer has recovered. Deprecated. Should not be used.

void BasicRecoverAsync(bool requeue)

Parameters

requeue bool

BasicReject(ulong, bool)

Reject a delivered message.

void BasicReject(ulong deliveryTag, bool requeue)

Parameters

deliveryTag ulong
requeue bool

Close()

Close this session.

void Close()

Remarks

If the session is already closed (or closing), then this method does nothing but wait for the in-progress close operation to complete. This method will not return to the caller until the shutdown is complete.

Close(ushort, string)

Close this session.

void Close(ushort replyCode, string replyText)

Parameters

replyCode ushort
replyText string

Remarks

The method behaves in the same way as Close(), with the only difference that the model is closed with the given model close code and message.

The close code (See under "Reply Codes" in the AMQP specification)

A message indicating the reason for closing the model

ConfirmSelect()

Enable publisher acknowledgements.

void ConfirmSelect()

ConsumerCount(string)

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.

uint ConsumerCount(string queue)

Parameters

queue string

The name of the queue

Returns

uint

CreateBasicProperties()

Construct a completely empty content header for use with the Basic content class.

IBasicProperties CreateBasicProperties()

Returns

IBasicProperties

CreateBasicPublishBatch()

Creates a BasicPublishBatch instance

IBasicPublishBatch CreateBasicPublishBatch()

Returns

IBasicPublishBatch

ExchangeBind(string, string, string, IDictionary<string, object>)

Bind an exchange to an exchange.

void ExchangeBind(string destination, string source, string routingKey, IDictionary<string, object> arguments)

Parameters

destination string
source string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

ExchangeBindNoWait(string, string, string, IDictionary<string, object>)

Like ExchangeBind but sets nowait to true.

void ExchangeBindNoWait(string destination, string source, string routingKey, IDictionary<string, object> arguments)

Parameters

destination string
source string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

ExchangeDeclare(string, string, bool, bool, IDictionary<string, object>)

Declare an exchange.

void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, IDictionary<string, object> arguments)

Parameters

exchange string
type string
durable bool
autoDelete bool
arguments IDictionary<string, object>

Remarks

The exchange is declared non-passive and non-internal. The "nowait" option is not exercised.

ExchangeDeclareNoWait(string, string, bool, bool, IDictionary<string, object>)

Same as ExchangeDeclare but sets nowait to true and returns void (as there will be no response from the server).

void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool autoDelete, IDictionary<string, object> arguments)

Parameters

exchange string
type string
durable bool
autoDelete bool
arguments IDictionary<string, object>

ExchangeDeclarePassive(string)

Do a passive exchange declaration.

void ExchangeDeclarePassive(string exchange)

Parameters

exchange string

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.

ExchangeDelete(string, bool)

Delete an exchange.

void ExchangeDelete(string exchange, bool ifUnused)

Parameters

exchange string
ifUnused bool

ExchangeDeleteNoWait(string, bool)

Like ExchangeDelete but sets nowait to true.

void ExchangeDeleteNoWait(string exchange, bool ifUnused)

Parameters

exchange string
ifUnused bool

ExchangeUnbind(string, string, string, IDictionary<string, object>)

Unbind an exchange from an exchange.

void ExchangeUnbind(string destination, string source, string routingKey, IDictionary<string, object> arguments)

Parameters

destination string
source string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

ExchangeUnbindNoWait(string, string, string, IDictionary<string, object>)

Like ExchangeUnbind but sets nowait to true.

void ExchangeUnbindNoWait(string destination, string source, string routingKey, IDictionary<string, object> arguments)

Parameters

destination string
source string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

MessageCount(string)

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.

uint MessageCount(string queue)

Parameters

queue string

The name of the queue

Returns

uint

QueueBind(string, string, string, IDictionary<string, object>)

Bind a queue to an exchange.

void QueueBind(string queue, string exchange, string routingKey, IDictionary<string, object> arguments)

Parameters

queue string
exchange string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

QueueBindNoWait(string, string, string, IDictionary<string, object>)

Same as QueueBind but sets nowait parameter to true.

void QueueBindNoWait(string queue, string exchange, string routingKey, IDictionary<string, object> arguments)

Parameters

queue string
exchange string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

QueueDeclare(string, bool, bool, bool, IDictionary<string, object>)

Declares a queue. See the Queues guide to learn more.

QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments)

Parameters

queue string

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

durable bool

Should this queue will 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"

Returns

QueueDeclareOk

QueueDeclareNoWait(string, bool, bool, bool, IDictionary<string, object>)

Same as QueueDeclare but sets nowait to true and returns void (as there will be no response from the server).

void QueueDeclareNoWait(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments)

Parameters

queue string
durable bool
exclusive bool
autoDelete bool
arguments IDictionary<string, object>

QueueDeclarePassive(string)

Declare a queue passively.

QueueDeclareOk QueueDeclarePassive(string queue)

Parameters

queue string

Returns

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.

QueueDelete(string, bool, bool)

Delete a queue.

uint QueueDelete(string queue, bool ifUnused, bool ifEmpty)

Parameters

queue string
ifUnused bool
ifEmpty bool

Returns

uint

Remarks

Returns the number of messages purged during queue deletion.

uint.MaxValue
.

QueueDeleteNoWait(string, bool, bool)

Same as QueueDelete but sets nowait parameter to true and returns void (as there will be no response from the server)

void QueueDeleteNoWait(string queue, bool ifUnused, bool ifEmpty)

Parameters

queue string
ifUnused bool
ifEmpty bool

QueuePurge(string)

Purge a queue of messages.

uint QueuePurge(string queue)

Parameters

queue string

Returns

uint

Remarks

Returns the number of messages purged.

QueueUnbind(string, string, string, IDictionary<string, object>)

Unbind a queue from an exchange.

void QueueUnbind(string queue, string exchange, string routingKey, IDictionary<string, object> arguments)

Parameters

queue string
exchange string
routingKey string
arguments IDictionary<string, object>

Remarks

Routing key must be shorter than 255 bytes.

TxCommit()

Commit this session's active TX transaction.

void TxCommit()

TxRollback()

Roll back this session's active TX transaction.

void TxRollback()

TxSelect()

Enable TX mode for this session.

void TxSelect()

WaitForConfirms()

Wait until all published messages have been confirmed.

bool WaitForConfirms()

Returns

bool

Remarks

Waits until all messages published since the last call have been either ack'd or nack'd by the broker. Returns whether all the messages were ack'd (and none were nack'd). Note, throws an exception when called on a non-Confirm channel.

WaitForConfirms(TimeSpan)

Wait until all published messages have been confirmed.

bool WaitForConfirms(TimeSpan timeout)

Parameters

timeout TimeSpan

How long to wait (at most) before returning whether or not any nacks were returned.

Returns

bool

True if no nacks were received within the timeout, otherwise false.

Remarks

Waits until all messages published since the last call have been either ack'd or nack'd by the broker. Returns whether all the messages were ack'd (and none were nack'd). Note, throws an exception when called on a non-Confirm channel.

WaitForConfirms(TimeSpan, out bool)

Wait until all published messages have been confirmed.

bool WaitForConfirms(TimeSpan timeout, out bool timedOut)

Parameters

timeout TimeSpan

How long to wait (at most) before returning whether or not any nacks were returned.

timedOut bool

True if the method returned because the timeout elapsed, not because all messages were ack'd or at least one nack'd.

Returns

bool

True if no nacks were received within the timeout, otherwise false.

Remarks

Waits until all messages published since the last call have been either ack'd or nack'd by the broker. Returns whether all the messages were ack'd (and none were nack'd). Note, throws an exception when called on a non-Confirm channel.

WaitForConfirmsOrDie()

Wait until all published messages on this channel have been confirmed.

void WaitForConfirmsOrDie()

Remarks

Waits until all messages published on this channel since the last call have been ack'd by the broker. If a nack is received, throws an OperationInterrupedException exception immediately and closes the channel.

WaitForConfirmsOrDie(TimeSpan)

Wait until all published messages on this channel have been confirmed.

void WaitForConfirmsOrDie(TimeSpan timeout)

Parameters

timeout TimeSpan

Remarks

Waits until all messages published on this channel since the last call have been ack'd by the broker. If a nack is received or the timeout elapses, throws an OperationInterruptedException exception immediately and closes the channel.

Events

BasicAcks

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

event EventHandler<BasicAckEventArgs> BasicAcks

Event Type

EventHandler<BasicAckEventArgs>

BasicNacks

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

event EventHandler<BasicNackEventArgs> BasicNacks

Event Type

EventHandler<BasicNackEventArgs>

BasicRecoverOk

All messages received before this fires that haven't been ack'ed will be redelivered. All messages received afterwards won't be.

event EventHandler<EventArgs> BasicRecoverOk

Event Type

EventHandler<EventArgs>

Remarks

Handlers for this event are invoked by the connection thread. It is sometimes useful to allow that thread to know that a recover-ok has been received, rather than the thread that invoked BasicRecover(bool).

BasicReturn

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

event EventHandler<BasicReturnEventArgs> BasicReturn

Event Type

EventHandler<BasicReturnEventArgs>

CallbackException

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

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

event EventHandler<CallbackExceptionEventArgs> CallbackException

Event Type

EventHandler<CallbackExceptionEventArgs>

FlowControl

event EventHandler<FlowControlEventArgs> FlowControl

Event Type

EventHandler<FlowControlEventArgs>

ModelShutdown

Notifies the destruction of the model.

event EventHandler<ShutdownEventArgs> ModelShutdown

Event Type

EventHandler<ShutdownEventArgs>

Remarks

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