Permalink
Browse files

Make it possible to define more chan one basic.cancel handler

One is now defined by automatic consumer recovery, so there should
be a way for the user to define additional ones.
  • Loading branch information...
1 parent ffc8227 commit 1f23bfe8c7352eafa3727ad6dd76b999b8488093 Michael Klishin committed Feb 21, 2014
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/bunny/consumer.rb
View
@@ -39,6 +39,8 @@ def initialize(channel, queue, consumer_tag = channel.generate_consumer_tag, no_
@arguments = arguments
# no_ack set to true = no manual ack = automatic ack. MK.
@no_ack = no_ack
+
+ @on_cancellation = []
end
# Defines message delivery handler
@@ -61,14 +63,16 @@ def call(*args)
# @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

0 comments on commit 1f23bfe

Please sign in to comment.