Complete the code to declare a queue in RabbitMQ.
channel.queue_declare(queue='[1]')
The queue_declare method creates or checks a queue named 'task_queue'. This is where messages are stored.
Complete the code to send a message to the queue.
channel.basic_publish(exchange='', routing_key='[1]', body='Hello World!')
The routing_key specifies the queue name to send the message to. Here, it is 'task_queue'.
Fix the error in the code to consume messages from the queue.
channel.basic_consume(queue='[1]', on_message_callback=callback, auto_ack=True)
The queue parameter must be the queue name to consume messages from, here 'task_queue'.
Fill both blanks to create a durable queue and send a persistent message.
channel.queue_declare(queue='[1]', durable=[2]) channel.basic_publish(exchange='', routing_key='task_queue', body='Important', properties=pika.BasicProperties(delivery_mode=2))
Setting durable=True makes the queue survive server restarts. The queue name is 'task_queue'. The message is marked persistent with delivery_mode=2.
Fill all three blanks to set up a consumer with manual message acknowledgment.
def callback(ch, method, properties, body): print(f"Received {body}") ch.basic_ack(delivery_tag=[1]) channel.basic_consume(queue=[2], on_message_callback=callback, auto_ack=[3])
The delivery_tag is used to acknowledge the message manually. The queue is 'task_queue'. Setting auto_ack=False means manual acknowledgment is required.