Table of Contents

Class PublisherCallbackChannel

Namespace
Steeltoe.Messaging.RabbitMQ.Connection
Assembly
Steeltoe.Messaging.RabbitMQ.dll
public class PublisherCallbackChannel : IPublisherCallbackChannel, IModel, IDisposable
Inheritance
PublisherCallbackChannel
Implements
IModel
Inherited Members

Constructors

PublisherCallbackChannel(IModel, ILogger)

public PublisherCallbackChannel(IModel channel, ILogger logger = null)

Parameters

channel IModel
logger ILogger

Fields

RETURNED_MESSAGE_CORRELATION_KEY

public const string RETURNED_MESSAGE_CORRELATION_KEY = "spring_returned_message_correlation"

Field Value

string

RETURN_LISTENER_CORRELATION_KEY

public const string RETURN_LISTENER_CORRELATION_KEY = "spring_listener_return_correlation"

Field Value

string

RETURN_LISTENER_ERROR

public const string RETURN_LISTENER_ERROR = "No 'spring_listener_return_correlation' header in returned message"

Field Value

string

Properties

Channel

Gets the underlying RabbitMQ model

public virtual IModel Channel { get; }

Property Value

IModel

ChannelNumber

Channel number, unique per connections.

public virtual 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.

public virtual ShutdownEventArgs CloseReason { get; }

Property Value

ShutdownEventArgs

ContinuationTimeout

Amount of time protocol operations (e.g.

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

Property Value

TimeSpan

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

Property Value

IBasicConsumer

IsClosed

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

public virtual 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 RabbitMQ.Client.IModel.CloseReason equals null.

public virtual bool IsOpen { get; }

Property Value

bool

NextPublishSeqNo

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

public virtual ulong NextPublishSeqNo { get; }

Property Value

ulong

Methods

Abort()

Abort this session.

public virtual 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 RabbitMQ.Client.IModel.Close() method, RabbitMQ.Client.IModel.Abort() will not throw RabbitMQ.Client.Exceptions.AlreadyClosedException or IOException or any other Exception during closing model.

Abort(ushort, string)

Abort this session.

public virtual void Abort(ushort replyCode, string replyText)

Parameters

replyCode ushort
replyText string

Remarks

The method behaves in the same way as RabbitMQ.Client.IModel.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

AddListener(IListener)

Add a publisher callback listener

public virtual void AddListener(IPublisherCallbackChannel.IListener listener)

Parameters

listener IPublisherCallbackChannel.IListener

the listener to add

AddPendingConfirm(IListener, ulong, PendingConfirm)

Add a pending confirmation to this channels map

public virtual void AddPendingConfirm(IPublisherCallbackChannel.IListener listener, ulong sequence, PendingConfirm pendingConfirm)

Parameters

listener IPublisherCallbackChannel.IListener

the listener the pending confir is for

sequence ulong

the key to the map

pendingConfirm PendingConfirm

the pending confirm

BasicAck(ulong, bool)

Acknowledge one or more delivered message(s).

public virtual void BasicAck(ulong deliveryTag, bool multiple)

Parameters

deliveryTag ulong
multiple bool

BasicCancel(string)

Delete a Basic content-class consumer.

public virtual void BasicCancel(string consumerTag)

Parameters

consumerTag string

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

Start a Basic content-class consumer.

public virtual 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).

public virtual BasicGetResult BasicGet(string queue, bool autoAck)

Parameters

queue string
autoAck bool

Returns

BasicGetResult

BasicNack(ulong, bool, bool)

Reject one or more delivered message(s).

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

Parameters

deliveryTag ulong
multiple bool
requeue bool

BasicPublish(string, string, bool, IBasicProperties, byte[])

Publishes a message.

public virtual void BasicPublish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body)

Parameters

exchange string
routingKey string
mandatory bool
basicProperties IBasicProperties
body byte[]

Remarks

Routing key must be shorter than 255 bytes.

BasicQos(uint, ushort, bool)

Configures QoS parameters of the Basic content-class.

public virtual 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.

public virtual void BasicRecover(bool requeue)

Parameters

requeue bool

BasicRecoverAsync(bool)

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

public virtual void BasicRecoverAsync(bool requeue)

Parameters

requeue bool

BasicReject(ulong, bool)

Reject a delivered message.

public virtual void BasicReject(ulong deliveryTag, bool requeue)

Parameters

deliveryTag ulong
requeue bool

Close()

Close this session.

public virtual 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.

public virtual 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.

public virtual 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.

public virtual 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.

public virtual IBasicProperties CreateBasicProperties()

Returns

IBasicProperties

CreateBasicPublishBatch()

Creates a BasicPublishBatch instance

public virtual IBasicPublishBatch CreateBasicPublishBatch()

Returns

IBasicPublishBatch

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

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

Bind an exchange to an exchange.

public virtual 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.

public virtual 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.

public virtual 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).

public virtual 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.

public virtual void ExchangeDeclarePassive(string exchange)

Parameters

exchange string

Remarks

This method performs a "passive declare" on an exchange, which verifies whether . 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.

public virtual void ExchangeDelete(string exchange, bool ifUnused)

Parameters

exchange string
ifUnused bool

ExchangeDeleteNoWait(string, bool)

Like ExchangeDelete but sets nowait to true.

public virtual void ExchangeDeleteNoWait(string exchange, bool ifUnused)

Parameters

exchange string
ifUnused bool

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

Unbind an exchange from an exchange.

public virtual 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.

public virtual 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.

Expire(IListener, long)

Expire (remove) any pending confirmations created before the specified cutoff time for the supplied listener and return them to the caller

public virtual IList<PendingConfirm> Expire(IPublisherCallbackChannel.IListener listener, long cutoffTime)

Parameters

listener IPublisherCallbackChannel.IListener

the listener

cutoffTime long

the time before which expired messages were created

Returns

IList<PendingConfirm>

the list of expired confirms

GetPendingConfirmsCount()

Gett the total pending confirm count

public virtual int GetPendingConfirmsCount()

Returns

int

the total count

GetPendingConfirmsCount(IListener)

Get the total pending confirm count for the listener

public virtual int GetPendingConfirmsCount(IPublisherCallbackChannel.IListener listener)

Parameters

listener IPublisherCallbackChannel.IListener

the listener to get confirm count for

Returns

int

the count of pending confirms

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.

public virtual 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.

public virtual 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.

public virtual 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>)

Declare a queue.

public virtual QueueDeclareOk QueueDeclare(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>

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).

public virtual 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.

public virtual 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.

public virtual 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)

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

Parameters

queue string
ifUnused bool
ifEmpty bool

QueuePurge(string)

Purge a queue of messages.

public virtual 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.

public virtual 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.

SetAfterAckCallback(Action<IModel>)

Set a callback to be invoked after the ack/nack has been handled

public virtual void SetAfterAckCallback(Action<IModel> callback)

Parameters

callback Action<IModel>

the callback

TxCommit()

Commit this session's active TX transaction.

public virtual void TxCommit()

TxRollback()

Roll back this session's active TX transaction.

public virtual void TxRollback()

TxSelect()

Enable TX mode for this session.

public virtual void TxSelect()

WaitForConfirms()

Wait until all published messages have been confirmed.

public virtual 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.

public virtual 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.

public virtual 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 have been confirmed.

public virtual void WaitForConfirmsOrDie()

Remarks

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

WaitForConfirmsOrDie(TimeSpan)

Wait until all published messages have been confirmed.

public virtual void WaitForConfirmsOrDie(TimeSpan timeout)

Parameters

timeout TimeSpan

Remarks

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

Events

BasicAcks

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

public virtual event EventHandler<BasicAckEventArgs> BasicAcks

Event Type

EventHandler<BasicAckEventArgs>

BasicNacks

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

public virtual 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.

public virtual 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.

public virtual 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 RabbitMQ.Client.IBasicConsumer methods, or exceptions thrown in RabbitMQ.Client.IModel.ModelShutdown delegates etc.

public virtual event EventHandler<CallbackExceptionEventArgs> CallbackException

Event Type

EventHandler<CallbackExceptionEventArgs>

FlowControl

public virtual event EventHandler<FlowControlEventArgs> FlowControl

Event Type

EventHandler<FlowControlEventArgs>

ModelShutdown

Notifies the destruction of the model.

public virtual 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.