From fefa1adaf753b5c3b195c278ed5170a4f9eca184 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Thu, 2 May 2019 11:37:57 +0200 Subject: [PATCH] PubSubConsumer: Fix cancel callbacks --- PubSubConsumer.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/PubSubConsumer.py b/PubSubConsumer.py index 9559175a..6a3027f5 100644 --- a/PubSubConsumer.py +++ b/PubSubConsumer.py @@ -255,18 +255,27 @@ class PubSubConsumer(object): self.logger.info('Received message # %s: %s %s', basic_deliver.delivery_tag, basic_deliver.routing_key, body) - def on_cancelok(self, unused_frame): + def on_cancelok(self, _unused_frame, userdata): """This method is invoked by pika when RabbitMQ acknowledges the cancellation of a consumer. At this point we will close the channel. This will invoke the on_channel_closed method once the channel has been closed, which will in-turn close the connection. - - :param pika.frame.Method unused_frame: The Basic.CancelOk frame - + :param pika.frame.Method _unused_frame: The Basic.CancelOk frame + :param str|unicode userdata: Extra user data (consumer tag) """ - self.logger.debug('RabbitMQ acknowledged the cancellation of the consumer') + self._consuming = False + self.logger.debug( + 'RabbitMQ acknowledged the cancellation of the consumer: %s', + userdata) self.close_channel() + def close_channel(self): + """Call to close the channel with RabbitMQ cleanly by issuing the + Channel.Close RPC command. + """ + self.logger.debug('Closing the channel') + self._channel.close() + def stop_consuming(self): """Tell RabbitMQ that you would like to stop consuming by sending the Basic.Cancel RPC command. @@ -308,14 +317,6 @@ class PubSubConsumer(object): else: self.start_consuming() - def close_channel(self): - """Call to close the channel with RabbitMQ cleanly by issuing the - Channel.Close RPC command. - - """ - self.logger.debug('Closing the channel') - self._channel.close() - def open_channel(self): """Open a new channel with RabbitMQ by issuing the Channel.Open RPC command. When RabbitMQ responds that the channel is open, the