Complete the code to declare a fanout exchange named 'logs'.
channel.exchange_declare(exchange='logs', exchange_type=[1])
The fanout exchange type broadcasts messages to all queues bound to it.
Complete the code to bind a queue named 'queue1' to the 'logs' fanout exchange.
channel.queue_bind(queue='queue1', exchange='logs', routing_key=[1])
For fanout exchanges, the routing key is ignored, so it is set to an empty string ''.
Fix the error in publishing a message to the 'logs' fanout exchange.
channel.basic_publish(exchange='logs', routing_key=[1], body='Hello World!')
When publishing to a fanout exchange, the routing key is ignored and should be an empty string ''.
Fill both blanks to declare a durable fanout exchange named 'broadcast' and bind 'queue2' to it.
channel.exchange_declare(exchange='broadcast', exchange_type=[1], durable=[2]) channel.queue_bind(queue='queue2', exchange='broadcast', routing_key='')
The exchange type must be 'fanout' for broadcast. Setting durable to True makes the exchange survive server restarts.
Fill all three blanks to publish a persistent message 'Update' to the 'broadcast' fanout exchange with empty routing key.
channel.basic_publish(exchange='broadcast', routing_key=[1], body='Update', properties=pika.BasicProperties(delivery_mode=[2], content_type=[3]))
For fanout exchange, routing_key is empty string ''. delivery_mode=2 makes the message persistent. content_type='text/plain' sets the message type.