lib/bunny/consumer.rb in bunny-1.1.5 vs lib/bunny/consumer.rb in bunny-1.1.6
- old
+ new
@@ -37,10 +37,12 @@
@consumer_tag = consumer_tag
@exclusive = exclusive
@arguments = arguments
# no_ack set to true = no manual ack = automatic ack. MK.
@no_ack = no_ack
+
+ @on_cancellation = []
end
# Defines message delivery handler
# @api public
def on_delivery(&block)
@@ -59,18 +61,20 @@
#
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
# @api public
def on_cancellation(&block)
- @on_cancellation = block
+ @on_cancellation << block
self
end
# Invokes consumer cancellation notification handler
# @private
def handle_cancellation(basic_cancel)
- @on_cancellation.call(basic_cancel) if @on_cancellation
+ @on_cancellation.each do |fn|
+ fn.call(basic_cancel)
+ end
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.
#
@@ -100,24 +104,25 @@
# @api public
def manual_acknowledgement?
@no_ack == false
end
+ # @return [String] Name of the queue this consumer is on
+ # @api public
+ def queue_name
+ if @queue.respond_to?(:name)
+ @queue.name
+ else
+ @queue
+ end
+ end
+
#
# Recovery
#
# @private
def recover_from_network_failure
@channel.basic_consume_with(self)
- end
-
- # @private
- def queue_name
- if @queue.respond_to?(:name)
- @queue.name
- else
- @queue
- end
end
end
end