public class QueueingBasicConsumer

Summary

A implementation that uses a to buffer incoming deliveries.

Remarks

Received messages are placed in the SharedQueue as instances of .

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

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

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;
                 }
             }
             

Property Summary

Flags Type Name Summary
public virtual final SharedQueue<BasicDeliverEventArgs> Queue (rw)

Retrieves the that messages arrive on.

Constructor Summary

Flags Name Summary
public QueueingBasicConsumer()

Creates a fresh , initialising the property to null and the property to a fresh .

public QueueingBasicConsumer(IModel model)

Creates a fresh , with set to the argument, and set to a fresh .

public QueueingBasicConsumer(IModel model, SharedQueue<BasicDeliverEventArgs> queue)

Creates a fresh , initialising the and properties to the given values.

Method Summary

Flags Name Summary
public virtual void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)

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

public virtual void OnCancel()

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

Property Detail

public virtual final SharedQueue<BasicDeliverEventArgs> Queue (rw)

Summary

Retrieves the that messages arrive on.

Constructor Detail

QueueingBasicConsumer

public QueueingBasicConsumer()

Summary

Creates a fresh , initialising the property to null and the property to a fresh .

QueueingBasicConsumer

public QueueingBasicConsumer(IModel model)

Parameters
Name Type
model IModel

Summary

Creates a fresh , with set to the argument, and set to a fresh .

QueueingBasicConsumer

public QueueingBasicConsumer(IModel model, SharedQueue<BasicDeliverEventArgs> queue)

Parameters
Name Type
model IModel
queue SharedQueue<BasicDeliverEventArgs>

Summary

Creates a fresh , initialising the and properties to the given values.

Method Detail

HandleBasicDeliver

public virtual void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)

Flags public virtual
Return type void
Parameters
Name Type
consumerTag string
deliveryTag ulong
redelivered bool
exchange string
routingKey string
properties IBasicProperties
body byte[]

Summary

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

OnCancel

public virtual void OnCancel()

Flags public virtual
Return type void

Summary

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