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