On Tue, 2012-10-09 at 16:46:05 +0400, Michael Klishin wrote:
> 2012/10/9 Simon Lundstr�m <
si...@su.se>
>
> > I've tried to put on_cancel in multiple ways, but never succeded
> > (because @default_consumer is nil).
> > on_cancel gets mixed into the Queue class and when on_cancel is called
> > it calls itself on the @default_consumer instance variable
> >
>
> default consumer is a relic from the pre-0.8 days or so when there was (an
> artificial) limitation that
> one AMQP::Queue instance can only have 1 consumer (added via
> AMQP::Queue#subscribe). That's not really how other clients work and
> there may be good reasons to have multiple consumers on a shared queue in
> different threads even on MRI.
>
> So sounds like we need to extend cancellation notifications to other
> consumers (find the consumer by
> consumer tag and invoke the callback on it). I will look into this this
> evening.
Just for future reference and to close this thread:
I talked to Michael on IRC and CCN works since 0.9.5.
I was writing my consumer wrong and Michael kindly added an integration
test[1] which can be used as inspiration on how to use CCN.
To auto-recovery a queue on CCN, we used this code:
queue = AMQ::Client::Queue.new(connection, channel, "example.ha.queue")
queue.declare(false, true, false, false, false, { "x-ha-policy" => "all" }) do
queue.consume {
queue.on_cancel {
queue.auto_recover
}
}
end
Note that this *only* recovers the queue when switching HA masters. This
does *not* recover the channel if you are, e.g., disconnected.
So channel recovery is needed too!
And remember, because I forgot and it took *quite* some time for me to
understand why it wouldn't work (it was a friday and I was tired = D), to:
require "amq/client/extensions/rabbitmq"
Otherwise AMQP never will announce to RabbitMQ that it supports CCN so
RabbitMQ will never send any basic.cancel's!
Have a nice weekend!
- Simon
1) <
https://github.com/ruby-amqp/amq-client/blob/master/spec/integration/eventmachine/consumer_cancellation_notification_spec.rb>