Complete the code to acknowledge a message manually in RabbitMQ consumer.
channel.basic_ack(delivery_tag=[1])The delivery_tag uniquely identifies the message to acknowledge. It is accessed via method.delivery_tag in the callback.
Complete the code to enable automatic acknowledgment in RabbitMQ consumer.
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[1])
Setting auto_ack=True tells RabbitMQ to automatically consider messages acknowledged once delivered.
Fix the error in the manual acknowledgment code by completing the blank.
def callback(ch, method, properties, body): print(f"Received {body}") ch.basic_ack(delivery_tag=[1])
The delivery_tag is part of the method parameter, not properties or others.
Fill both blanks to reject a message and requeue it in RabbitMQ consumer.
channel.basic_reject(delivery_tag=[1], requeue=[2])
To reject and requeue a message, use method.delivery_tag and set requeue=True.
Fill all three blanks to consume messages with manual ack and reject unprocessable messages without requeue.
def callback(ch, method, properties, body): try: process(body) ch.basic_ack(delivery_tag=[1]) except Exception: ch.basic_reject(delivery_tag=[2], requeue=[3]) channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False)
Use method.delivery_tag for both ack and reject. Set requeue=False to discard unprocessable messages.