Complete the code to consume a message from the queue.
channel.basic_consume(queue='task_queue', on_message_callback=[1], auto_ack=True)
The on_message_callback parameter requires a function that will be called when a message is received. This function processes the message.
Complete the code to start consuming messages.
channel.[1]()basic_publish which sends messages instead of receiving.stop_consuming which stops the consumer.The start_consuming() method tells the channel to begin waiting for messages and call the callback when messages arrive.
Fix the error in the callback function to acknowledge the message.
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 and is used to acknowledge the specific message.
Fill both blanks to consume messages with manual acknowledgment.
channel.basic_consume(queue=[1], on_message_callback=[2], auto_ack=False)
The queue name must be the one declared earlier, and the callback function processes the messages. Setting auto_ack=False means you manually acknowledge messages.
Fill all three blanks to set up a consumer with a callback and start consuming.
channel.basic_consume(queue=[1], on_message_callback=[2], auto_ack=[3]) channel.start_consuming()
auto_ack to True when manual ack is needed.This sets up consuming from the 'task_queue' with the callback function and manual acknowledgment (auto_ack=False), then starts the consumer loop.