Object
Base class that represents consumer interface. Subclasses of this class implement specific logic of handling consumer life cycle events. Note that when the only event you are interested in is message deliveries, it is recommended to just use {Bunny::Queue#subscribe} instead of subclassing this class.
@see Bunny::Queue#subscribe @see Bunny::Queue#subscribe_with @see rubybunny.info/articles/queues.html Queues and Consumers guide @api public
@param [Bunny::Channel] channel Channel this consumer will use @param [Bunny::Queue,String] queue Queue messages will be consumed from @param [String] consumer_tag Consumer tag (unique identifier). Generally it is better to let Bunny generate one.
Empty string means RabbitMQ will generate consumer tag.
@param [Boolean] no_ack (false) If false, delivered messages will be automatically acknowledged.
If true, manual acknowledgements will be necessary.
@param [Boolean] exclusive (false) Should this consumer be exclusive? @param [Hash] arguments (nil) Optional arguments that may be used by RabbitMQ extensions, etc @api public
# File lib/bunny/consumer.rb, line 34 def initialize(channel, queue, consumer_tag = channel.generate_consumer_tag, no_ack = true, exclusive = false, arguments = {}) @channel = channel || raise(ArgumentError, "channel is nil") @queue = queue || raise(ArgumentError, "queue is nil") @consumer_tag = consumer_tag @exclusive = exclusive @arguments = arguments @no_ack = no_ack end
Invokes message delivery handler @private
# File lib/bunny/consumer.rb, line 52 def call(*args) @on_delivery.call(*args) if @on_delivery end
Cancels this consumer. Messages for this consumer will no longer be delivered. If the queue it was on is auto-deleted and this consumer was the last one, the queue will be deleted.
@see rubybunny.info/articles/queues.html Queues and Consumers guide @api public
# File lib/bunny/consumer.rb, line 78 def cancel @channel.basic_cancel(@consumer_tag) end
Invokes consumer cancellation notification handler @private
# File lib/bunny/consumer.rb, line 69 def handle_cancellation(basic_cancel) @on_cancellation.call(basic_cancel) if @on_cancellation end
@return [String] More detailed human-readable string representation of this consumer
# File lib/bunny/consumer.rb, line 83 def inspect "#<#{self.class.name}:#{object_id} @channel_id=#{@channel.number} @queue=#{self.queue_name}> @consumer_tag=#{@consumer_tag} @exclusive=#{@exclusive} @no_ack=#{@no_ack}>" end
Defines consumer cancellation notification handler
@see rubybunny.info/articles/queues.html Queues and Consumers guide @see rubybunny.info/articles/extensions.html RabbitMQ Extensions guide @api public
# File lib/bunny/consumer.rb, line 62 def on_cancellation(&block) @on_cancellation = block self end
Defines message delivery handler @api public
# File lib/bunny/consumer.rb, line 45 def on_delivery(&block) @on_delivery = block self end
@private
# File lib/bunny/consumer.rb, line 102 def queue_name if @queue.respond_to?(:name) @queue.name else @queue end end
Generated with the Darkfish Rdoc Generator 2.