Class DefaultBasicConsumer
Useful default/base implementation of IBasicConsumer. Subclass and override HandleBasicDeliver(string, ulong, bool, string, string, IBasicProperties, ReadOnlyMemory<byte>) in application code.
Inheritance
Implements
Inherited Members
Namespace: RabbitMQ.Client
Assembly: RabbitMQ.Client.dll
Syntax
public class DefaultBasicConsumer : IBasicConsumer
Remarks
Note that the "Handle*" methods run in the connection's thread! Consider using EventingBasicConsumer, which exposes events that can be subscribed to consumer messages.
Constructors
| Edit this page View SourceDefaultBasicConsumer()
Creates a new instance of an DefaultBasicConsumer.
Declaration
public DefaultBasicConsumer()
DefaultBasicConsumer(IModel)
Constructor which sets the Model property to the given value.
Declaration
public DefaultBasicConsumer(IModel model)
Parameters
Type | Name | Description |
---|---|---|
IModel | model | Common AMQP model. |
Properties
| Edit this page View SourceConsumerTags
Retrieve the consumer tags this consumer is registered as; to be used to identify this consumer, for example, when cancelling it with BasicCancel(string). This value is an array because a single consumer instance can be reused to consume on multiple channels.
Declaration
public string[] ConsumerTags { get; }
Property Value
Type | Description |
---|---|
string[] |
IsRunning
Returns true while the consumer is registered and expecting deliveries from the broker.
Declaration
public bool IsRunning { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
Model
Retrieve the IModel this consumer is associated with, for use in acknowledging received messages, for instance.
Declaration
public IModel Model { get; set; }
Property Value
Type | Description |
---|---|
IModel |
ShutdownReason
If our IModel shuts down, this property will contain a description of the reason for the shutdown. Otherwise it will contain null. See ShutdownEventArgs.
Declaration
public ShutdownEventArgs ShutdownReason { get; protected set; }
Property Value
Type | Description |
---|---|
ShutdownEventArgs |
Methods
| Edit this page View SourceHandleBasicCancel(string)
Called when the consumer is cancelled for reasons other than by a basicCancel: e.g. the queue has been deleted (either by this channel or by any other channel). See HandleBasicCancelOk(string) for notification of consumer cancellation due to basicCancel
Declaration
public virtual void HandleBasicCancel(string consumerTag)
Parameters
Type | Name | Description |
---|---|---|
string | consumerTag | Consumer tag this consumer is registered. |
HandleBasicCancelOk(string)
Called upon successful deregistration of the consumer from the broker.
Declaration
public virtual void HandleBasicCancelOk(string consumerTag)
Parameters
Type | Name | Description |
---|---|---|
string | consumerTag | Consumer tag this consumer is registered. |
HandleBasicConsumeOk(string)
Called upon successful registration of the consumer with the broker.
Declaration
public virtual void HandleBasicConsumeOk(string consumerTag)
Parameters
Type | Name | Description |
---|---|---|
string | consumerTag | Consumer tag this consumer is registered. |
HandleBasicDeliver(string, ulong, bool, string, string, IBasicProperties, ReadOnlyMemory<byte>)
Called each time a message is delivered for this consumer.
Declaration
public virtual void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory<byte> body)
Parameters
Type | Name | Description |
---|---|---|
string | consumerTag | |
ulong | deliveryTag | |
bool | redelivered | |
string | exchange | |
string | routingKey | |
IBasicProperties | properties | |
ReadOnlyMemory<byte> | body |
Remarks
This is a no-op implementation. It will not acknowledge deliveries via BasicAck(ulong, bool) if consuming in automatic acknowledgement mode. Subclasses must copy or fully use delivery body before returning. Accessing the body at a later point is unsafe as its memory can be already released.
HandleModelShutdown(object, ShutdownEventArgs)
Called when the model (channel) this consumer was registered on terminates.
Declaration
public virtual void HandleModelShutdown(object model, ShutdownEventArgs reason)
Parameters
Type | Name | Description |
---|---|---|
object | model | A channel this consumer was registered on. |
ShutdownEventArgs | reason | Shutdown context. |
OnCancel(params string[])
Default implementation - overridable in subclasses.
Declaration
public virtual void OnCancel(params string[] consumerTags)
Parameters
Type | Name | Description |
---|---|---|
string[] | consumerTags | The set of consumer tags that where cancelled |
Remarks
This default implementation simply sets the IsRunning property to false, and takes no further action.
Events
| Edit this page View SourceConsumerCancelled
Signalled when the consumer gets cancelled.
Declaration
public event EventHandler<ConsumerEventArgs> ConsumerCancelled
Event Type
Type | Description |
---|---|
EventHandler<ConsumerEventArgs> |