Complete the code to declare a RabbitMQ queue named 'task_queue'.
channel.queue_declare(queue=[1])The queue_declare method needs the queue name as a string. Here, 'task_queue' is the correct queue name.
Complete the code to publish a message 'Hello World!' to the default exchange with routing key 'task_queue'.
channel.basic_publish(exchange='', routing_key=[1], body='Hello World!')
The routing key should be the queue name 'task_queue' to send the message to that queue.
Fix the error in the code to consume messages from 'task_queue' with a callback function named 'callback'.
channel.basic_consume(queue=[1], on_message_callback=callback, auto_ack=True)
The queue parameter must be the name of the queue to consume from, which is 'task_queue'.
Fill both blanks to declare a durable queue and publish a persistent message to it.
channel.queue_declare(queue=[1], durable=[2]) channel.basic_publish(exchange='', routing_key=[1], body='Important task', properties=pika.BasicProperties(delivery_mode=2))
Durable queues survive server restarts, so durable=True is needed. The queue name must be consistent in both places.
Fill all three blanks to create a direct exchange, bind a queue to it with a routing key, and publish a message.
channel.exchange_declare(exchange=[1], exchange_type=[2]) channel.queue_bind(queue=[3], exchange=[1], routing_key='info') channel.basic_publish(exchange=[1], routing_key='info', body='Log message')
A direct exchange routes messages with a specific routing key. The queue 'log_queue' is bound to the 'logs' exchange with routing key 'info'.