C# Class RabbitMQ.Client.QueueingBasicConsumer

Simple IBasicConsumer implementation that uses a SharedQueue to buffer incoming deliveries.

Received messages are placed in the SharedQueue as instances of BasicDeliverEventArgs.

Note that messages taken from the SharedQueue may need acknowledging with IModel.BasicAck.

When the consumer is closed, through BasicCancel or through the shutdown of the underlying IModel or IConnection, the SharedQueue's Close() method is called, which causes any Enqueue() operations, and Dequeue() operations when the queue is empty, to throw EndOfStreamException (see the comment for SharedQueue.Close()).

The following is a simple example of the usage of this class:

IModel channel = ...; QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel); channel.BasicConsume(queueName, null, consumer); // At this point, messages will be being asynchronously delivered, // and will be queueing up in consumer.Queue. while (true) { try { BasicDeliverEventArgs e = (BasicDeliverEventArgs) consumer.Queue.Dequeue(); // ... handle the delivery ... channel.BasicAck(e.DeliveryTag, false); } catch (EndOfStreamException ex) { // The consumer was cancelled, the model closed, or the // connection went away. break; } }
Inheritance: DefaultBasicConsumer
显示文件 Open project: rabbitmq/rabbitmq-dotnet-client Class Usage Examples

Public Methods

Method Description
HandleBasicDeliver ( string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte body ) : void

Overrides DefaultBasicConsumer's HandleBasicDeliver implementation, building a BasicDeliverEventArgs instance and placing it in the Queue.

OnCancel ( ) : void

Overrides DefaultBasicConsumer's OnCancel implementation, extending it to call the Close() method of the SharedQueue.

QueueingBasicConsumer ( ) : System

Creates a fresh QueueingBasicConsumer, initialising the DefaultBasicConsumer.Model property to null and the Queue property to a fresh SharedQueue.

QueueingBasicConsumer ( IModel model ) : System

Creates a fresh QueueingBasicConsumer, with DefaultBasicConsumer.Model set to the argument, and Queue set to a fresh SharedQueue.

QueueingBasicConsumer ( IModel model, SharedQueue queue ) : System

Creates a fresh QueueingBasicConsumer, initialising the DefaultBasicConsumer.Model and Queue properties to the given values.

Method Details

HandleBasicDeliver() public method

Overrides DefaultBasicConsumer's HandleBasicDeliver implementation, building a BasicDeliverEventArgs instance and placing it in the Queue.
public HandleBasicDeliver ( string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte body ) : void
consumerTag string
deliveryTag ulong
redelivered bool
exchange string
routingKey string
properties IBasicProperties
body byte
return void

OnCancel() public method

Overrides DefaultBasicConsumer's OnCancel implementation, extending it to call the Close() method of the SharedQueue.
public OnCancel ( ) : void
return void

QueueingBasicConsumer() public method

Creates a fresh QueueingBasicConsumer, initialising the DefaultBasicConsumer.Model property to null and the Queue property to a fresh SharedQueue.
public QueueingBasicConsumer ( ) : System
return System

QueueingBasicConsumer() public method

Creates a fresh QueueingBasicConsumer, with DefaultBasicConsumer.Model set to the argument, and Queue set to a fresh SharedQueue.
public QueueingBasicConsumer ( IModel model ) : System
model IModel
return System

QueueingBasicConsumer() public method

Creates a fresh QueueingBasicConsumer, initialising the DefaultBasicConsumer.Model and Queue properties to the given values.
public QueueingBasicConsumer ( IModel model, SharedQueue queue ) : System
model IModel
queue SharedQueue
return System