public class DefaultBasicConsumer

Summary

Useful default/base implementation of IBasicConsumer. Subclass and override HandleBasicDeliver in application code.

Remarks

Note that the "Handle*" methods run in the connection's thread! Consider using QueueingBasicConsumer, which uses a SharedQueue instance to safely pass received messages across to user threads, or RabbitMQ.Client.MessagePatterns.Subscription, which manages resource declaration and binding in addition to providing a thread-safe interface.

Property Summary

Flags Type Name Summary
public string ConsumerTag (rw)

Retrieve the consumer tag this consumer is registered as; to be used when discussing this consumer with the server, for instance with IModel.BasicCancel().

public bool IsRunning (r)

Returns true while the consumer is registered and expecting deliveries from the broker.

public virtual final IModel Model (rw)

Retrieve the IModel instance this consumer is registered with.

public ShutdownEventArgs ShutdownReason (r)

If our IModel shuts down, this property will contain a description of the reason for the shutdown. Otherwise it will contain null. See ShutdownEventArgs.

Constructor Summary

Flags Name Summary
public DefaultBasicConsumer(IModel model)

Constructor which sets the Model property to the given value.

public DefaultBasicConsumer()

Default constructor.

Method Summary

Flags Name Summary
public virtual void HandleBasicCancelOk(string consumerTag)

Default implementation - calls OnCancel().

public virtual void HandleBasicConsumeOk(string consumerTag)

Default implementation - sets the ConsumerTag property and sets IsRunning to true.

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

Default implementation - override in subclasses.

public virtual void HandleModelShutdown(IModel model, ShutdownEventArgs reason)

Default implementation - sets ShutdownReason and calls OnCancel().

public virtual void OnCancel()

Default implementation - overridable in subclasses.

Property Detail

public string ConsumerTag (rw)

Summary

Retrieve the consumer tag this consumer is registered as; to be used when discussing this consumer with the server, for instance with IModel.BasicCancel().

public bool IsRunning (r)

Summary

Returns true while the consumer is registered and expecting deliveries from the broker.

public virtual final IModel Model (rw)

Summary

Retrieve the IModel instance this consumer is registered with.

public ShutdownEventArgs ShutdownReason (r)

Summary

If our IModel shuts down, this property will contain a description of the reason for the shutdown. Otherwise it will contain null. See ShutdownEventArgs.

Constructor Detail

DefaultBasicConsumer

public DefaultBasicConsumer(IModel model)

Parameters
Name Type
model IModel

Summary

Constructor which sets the Model property to the given value.

DefaultBasicConsumer

public DefaultBasicConsumer()

Summary

Default constructor.

Method Detail

HandleBasicCancelOk

public virtual void HandleBasicCancelOk(string consumerTag)

Flags public virtual
Return type void
Parameters
Name Type
consumerTag string

Summary

Default implementation - calls OnCancel().

HandleBasicConsumeOk

public virtual void HandleBasicConsumeOk(string consumerTag)

Flags public virtual
Return type void
Parameters
Name Type
consumerTag string

Summary

Default implementation - sets the ConsumerTag property and sets IsRunning to true.

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

Default implementation - override in subclasses.

Remarks

Does nothing with the passed in information. Note that in particular, some delivered messages may require acknowledgement via IModel.BasicAck; the implementation of this method in this class does NOT acknowledge such messages.

HandleModelShutdown

public virtual void HandleModelShutdown(IModel model, ShutdownEventArgs reason)

Flags public virtual
Return type void
Parameters
Name Type
model IModel
reason ShutdownEventArgs

Summary

Default implementation - sets ShutdownReason and calls OnCancel().

OnCancel

public virtual void OnCancel()

Flags public virtual
Return type void

Summary

Default implementation - overridable in subclasses.

Remarks

This default implementation simply sets the IsRunning property to false, and takes no further action.