Exemple #1
0
    def _on_cancel(self, method_frame):
        """Raises a ConsumerCanceled exception after processing the frame


        :param pika.frame.Method method_frame: The method frame received

        """
        super(BlockingChannel, self)._on_cancel(method_frame)
        raise exceptions.ConsumerCancelled(method_frame.method)
 def _clear_consumer(ret, queue_name):
     for consumer_tag in list(
             self._queue_name_to_consumer_tags.get(queue_name, set())):
         self._consumers[consumer_tag].close(
             exceptions.ConsumerCancelled("Queue %s was deleted." %
                                          queue_name))
         del self._consumers[consumer_tag]
         self._queue_name_to_consumer_tags[queue_name].remove(
             consumer_tag)
     return ret
Exemple #3
0
    def request_closed(self, err, request, queue_name):
        """
        Remove a request from the map of queues to open requests.

        This is intended to be called when a request is finished or closed.
        It can be added to a request by using ``request.notifyFinish``.

        :param err:         unused
        :param queue_name:  The name of the queue the request is attached to in
                            self.subscribers
        :type  queue_name:  str
        :param request:     The request to remove from self.subscribers
        """
        _log.debug('Removing ' + str(request) + ' from ' + str(queue_name))
        subscriber = self.subscribers[queue_name]
        subscriber['requests'].remove(request)
        if len(subscriber['requests']) == 0 and subscriber['queue']:
            # We need to notify the AMQP server so it stops pushing messages
            subscription = subscriber['queue']
            yield self.channel.basic_cancel(consumer_tag=subscription.consumer_tag)
            subscription.queue.close(pika_exceptions.ConsumerCancelled())
            self.subscribers.pop(queue_name)
Exemple #4
0
    def _on_consumer_cancelled(self, frame):
        """Called when the broker cancels a consumer via Basic.Cancel or when
        the broker responds to a Basic.Cancel request by Basic.CancelOk.

        :param pika.frame.Method frame: method frame with the
            `spec.Basic.Cancel` or `spec.Basic.CancelOk` method

        """
        consumer_tag = frame.method.consumer_tag
        if consumer_tag not in self._consumers:
            # Could be cancelled by user or broker earlier
            LOGGER.warning('basic_cancel - consumer not found: %s',
                           consumer_tag)
            return frame
        self._consumers[consumer_tag].close(exceptions.ConsumerCancelled())
        del self._consumers[consumer_tag]
        # Remove from the queue-to-ctags index:
        for ctags in self._queue_name_to_consumer_tags.values():
            try:
                ctags.remove(consumer_tag)
            except KeyError:
                continue
        return frame