Complete the code to declare a fanout exchange named 'logs'.
channel.exchange_declare(exchange='logs', exchange_type=[1])
The fanout exchange broadcasts messages to all queues bound to it.
Complete the code to publish a message 'Hello World!' to the 'logs' exchange.
channel.basic_publish(exchange='logs', routing_key=[1], body='Hello World!')
For a fanout exchange, the routing key is ignored, so an empty string is used.
Fix the error in the code to bind a queue named 'task_queue' to the 'logs' exchange.
channel.queue_bind(queue='task_queue', exchange='logs', routing_key=[1])
When binding a queue to a fanout exchange, the routing key must be an empty string.
Fill both blanks to declare a durable queue and bind it to the 'logs' fanout exchange.
channel.queue_declare(queue=[1], durable=[2]) channel.queue_bind(queue=[1], exchange='logs', routing_key='')
The queue name is 'task_queue' and it is declared durable to survive RabbitMQ restarts.
Fill all three blanks to create a callback function that prints received messages, start consuming from 'task_queue', and acknowledge messages.
def callback(ch, method, properties, body): print([1]) ch.basic_ack(delivery_tag=[2]) channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[3]) channel.start_consuming()
The callback prints the decoded message body, acknowledges the message using delivery_tag, and disables auto-acknowledge to manually ack.