Publish Subscribe : Sending messages to many consumers at once

This part of the tutorial introduce exchange.

A scripts publish messages into a fanout exchange. Then the script creates a temporary queue (which is deleted on the disconnection).

If the script is ran multiple times, all the instance will receive the message emitted by emit_log.


The publisher create a new fanout exchange:

yield from channel.exchange_declare(exchange_name='logs', type_name='fanout'

And publish message into that exchange:

yield from channel.basic_publish(message, exchange_name='logs', routing_key='')


The consumer create a temporary queue and binds it to the exchange.

yield from'logs', type_name='fanout')
# let RabbitMQ generate a random queue name
result = yield from channel.queue(queue_name='', exclusive=True)

queue_name = result['queue']
yield from channel.queue_bind(exchange_name='logs', queue_name=queue_name, routing_key='')