MCPcopy
hub / github.com/pika/pika / basic_consume

Method basic_consume

pika/channel.py:313–385  ·  view source on GitHub ↗

Sends the AMQP 0-9-1 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_consu

(
            self,
            queue: str,
            on_message_callback: _OnMessageCallback,
            auto_ack: bool = False,
            exclusive: bool = False,
            consumer_tag: Optional[str] = None,
            arguments: Optional[Dict[str, Any]] = None,
            callback: Optional[_OnBasicConsumeCallback] = None)

Source from the content-addressed store, hash-verified

311 })] if not nowait else [])
312
313 def basic_consume(
314 self,
315 queue: str,
316 on_message_callback: _OnMessageCallback,
317 auto_ack: bool = False,
318 exclusive: bool = False,
319 consumer_tag: Optional[str] = None,
320 arguments: Optional[Dict[str, Any]] = None,
321 callback: Optional[_OnBasicConsumeCallback] = None) -> str:
322 """Sends the AMQP 0-9-1 command Basic.Consume to the broker and binds messages
323 for the consumer_tag to the consumer callback. If you do not pass in
324 a consumer_tag, one will be automatically generated for you. Returns
325 the consumer tag.
326
327 For more information on basic_consume, see:
328 Tutorial 2 at https://www.rabbitmq.com/getstarted.html
329 https://www.rabbitmq.com/confirms.html
330 https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume
331
332 :param str queue: The queue to consume from. Use the empty string to
333 specify the most recent server-named queue for this channel
334 :param callable on_message_callback: The function to call when
335 consuming with the signature
336 on_message_callback(channel, method, properties, body), where
337 - channel: pika.channel.Channel
338 - method: pika.spec.Basic.Deliver
339 - properties: pika.spec.BasicProperties
340 - body: bytes
341 :param bool auto_ack: if set to True, automatic acknowledgement mode
342 will be used (see https://www.rabbitmq.com/confirms.html).
343 This corresponds with the 'no_ack' parameter in the basic.consume
344 AMQP 0.9.1 method
345 :param bool exclusive: Don't allow other consumers on the queue
346 :param str consumer_tag: Specify your own consumer tag
347 :param dict arguments: Custom key/value pair arguments for the consumer
348 :param callable callback: callback(pika.frame.Method) for method
349 Basic.ConsumeOk.
350 :returns: Consumer tag which may be used to cancel the consumer.
351 :rtype: str
352 :raises ValueError:
353
354 """
355 validators.require_string(queue, 'queue')
356 validators.require_callback(on_message_callback)
357 self._raise_if_not_open()
358 validators.rpc_completion_callback(callback)
359
360 # If a consumer tag was not passed, create one
361 if not consumer_tag:
362 consumer_tag = self._generate_consumer_tag()
363
364 if consumer_tag in self._consumers or consumer_tag in self._cancelled:
365 raise exceptions.DuplicateConsumerTag(consumer_tag)
366
367 if auto_ack:
368 self._consumers_with_noack.add(consumer_tag)
369
370 self._consumers[consumer_tag] = on_message_callback

Calls 4

_raise_if_not_openMethod · 0.95
_rpcMethod · 0.95
addMethod · 0.80