The Fanout Exchange is an even simpler, but slightly less popular way of routing in RabbitMQ. This type of exchange sends messages to all queues subscribed to it, ignoring any arguments of the message.
At the same time, if the queue listens to several consumers, messages will also be distributed among them (default scaling mechanism).
@broker.subscriber(queue_1,exch)asyncdefbase_handler1(logger:Logger):logger.info("base_handler1")@broker.subscriber(queue_1,exch)# another serviceasyncdefbase_handler2(logger:Logger):logger.info("base_handler2")@broker.subscriber(queue_2,exch)asyncdefbase_handler3(logger:Logger):logger.info("base_handler3")
Note
handler1 and handler2 are subscribed to the same exchange using the same queue: within a single service, this does not make sense, since messages will come to these handlers in turn. Here we emulate the work of several consumers and load balancing between them.