def basic_consume(self, consumer_callback, queue='', no_ack=False, exclusive=False, consumer_tag=None, arguments=None): self._validate_connection_and_channel() if not consumer_tag: consumer_tag = self._generate_consumer_tag() if consumer_tag in self._consumers: raise exceptions.DuplicateConsumerTag(consumer_tag) if no_ack: self._consumers_with_noack.add(consumer_tag) self._consumers[consumer_tag] = consumer_callback self.rpc( spec.Basic.Consume(queue=queue, consumer_tag=consumer_tag, no_ack=no_ack, exclusive=exclusive, arguments=arguments or dict()), [(spec.Basic.ConsumeOk, { 'consumer_tag': consumer_tag })]) return consumer_tag
def basic_consume(self, consumer_callback, queue='', no_ack=False, exclusive=False, consumer_tag=None, arguments=None): """Sends the AMQP command Basic.Consume to the broker and binds messages for the consumer_tag to the consumer callback. If you do not pass in a consumer_tag, one will be automatically generated for you. Returns the consumer tag. For more information on basic_consume, see: http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume :param method consumer_callback: The method to callback when consuming :param queue: The queue to consume from :type queue: str or unicode :param bool no_ack: Tell the broker to not expect a response :param bool exclusive: Don't allow other consumers on the queue :param consumer_tag: Specify your own consumer tag :type consumer_tag: str or unicode :param dict arguments: Custom key/value pair arguments for the consume :rtype: str """ self._validate_channel_and_callback(consumer_callback) # If a consumer tag was not passed, create one consumer_tag = consumer_tag or 'ctag%i.%s' % (self.channel_number, uuid.uuid4().get_hex()) if consumer_tag in self._consumers or consumer_tag in self._cancelled: raise exceptions.DuplicateConsumerTag(consumer_tag) self._consumers[consumer_tag] = consumer_callback self._pending[consumer_tag] = list() self._rpc( spec.Basic.Consume(queue=queue, consumer_tag=consumer_tag, no_ack=no_ack, exclusive=exclusive, arguments=arguments or dict()), self._on_eventok, [(spec.Basic.ConsumeOk, { 'consumer_tag': consumer_tag })]) return consumer_tag
def basic_consume(self, consumer_callback, queue='', no_ack=False, exclusive=False, consumer_tag=None): """ Sends the AMQP command Basic.Consume to the broker and binds messages for the consumer_tag to the consumer callback. If you do not pass in a consumer_tag, one will be automatically generated for you. Returns the consumer tag. For more information on basic_consume, see: http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume """ # If a consumer tag was not passed, create one if not consumer_tag: consumer_tag = 'ctag%i.%i' % (self.channel_number, len(self._consumers)) # Make sure we've not already registered this consumer tag if consumer_tag in self._consumers: raise exceptions.DuplicateConsumerTag(consumer_tag) # The consumer tag has not been used before, add it to our consumers self._consumers[consumer_tag] = consumer_callback # Setup a list for appending frames into self._pending[consumer_tag] = list() # Send our Basic.Consume RPC call try: self.transport.rpc( spec.Basic.Consume(queue=queue, consumer_tag=consumer_tag, no_ack=no_ack, exclusive=exclusive), self.transport._on_event_ok, [spec.Basic.ConsumeOk]) except exceptions.ChannelClosed, e: del (self._consumers[consumer_tag]) del (self._pending[consumer_tag]) raise exceptions.ChannelClosed(e)