DefaultBasicConsumer
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;
}
}
| Flags | Type | Name | Summary |
|---|---|---|---|
| public | SharedQueue |
Queue (r)
|
Retrieves the SharedQueue that messages arrive on. |
| Flags | Name | Summary |
|---|---|---|
| public | QueueingBasicConsumer(IModel model, SharedQueue queue)
|
Creates a fresh QueueingBasicConsumer, initialising the Model and Queue properties to the given values. |
| public | QueueingBasicConsumer(IModel model)
|
Creates a fresh QueueingBasicConsumer, with Model set to the argument, and Queue set to a fresh SharedQueue. |
| public | QueueingBasicConsumer()
|
Creates a fresh QueueingBasicConsumer, initialising the Model property to null and the Queue property to a fresh SharedQueue. |
| Flags | Name | Summary |
|---|---|---|
| public virtual | void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
|
Overrides DefaultBasicConsumer's HandleBasicDeliver implementation, building a BasicDeliverEventArgs instance and placing it in the Queue. |
| public virtual | void OnCancel()
|
Overrides DefaultBasicConsumer's OnCancel implementation, extending it to call the Close() method of the SharedQueue. |
public QueueingBasicConsumer(IModel model, SharedQueue queue)
| Parameters |
|
|---|
public QueueingBasicConsumer(IModel model)
| Parameters |
|
|---|
public QueueingBasicConsumer()
public virtual void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
| Flags | public virtual | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Return type | |
||||||||||||||||
| Parameters |
|