Use these RabbitMQ fanout exchange configurations if you're using RabbitMqBundle for symfony application. If you're using more than one consumers in your configs, consider using multiple_consumers config option instead. I have an example post somewhere that you can find and have a look into.


Fanout facts



Remember


After creating or updating queues/exchanges configs, you should always run $ bin/console rabbitmq:setup-fabric so that all queues/exchanges from your symfony config are synchronized with rabbitmq server otherwise published messages won't reach queues as they won't exist.


1 Producer & 1 Exchange & 1 Queue & N Worker & 1 Consumer


All order "create" messages would go to single queue.


# You can run many workers like commands below.
$ app/console rabbitmq:consumer -m 100 order_create
$ app/console rabbitmq:consumer -m 100 order_create

old_sound_rabbit_mq:
connections:
default:
host: 127.0.0.1
port: 5672
user: guest
password: guest
vhost: /
lazy: true
producers:
order_create:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
consumers:
order_create:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
queue_options: { name: 'order_create_qu' }
callback: application_frontend.consumer.order_create



1 Producer & 1 Exchange & 2 Queue & N Worker & 2 Consumer


If you want to process a message in two different ways by two different consumers, this option can be used. As we know, a copy of same message goes to both queues.


# You can run many workers like commands below.
$ app/console rabbitmq:consumer -m 100 order_create_1
$ app/console rabbitmq:consumer -m 100 order_create_1

$ app/console rabbitmq:consumer -m 100 order_create_2
$ app/console rabbitmq:consumer -m 100 order_create_2

old_sound_rabbit_mq:
connections:
default:
host: 127.0.0.1
port: 5672
user: guest
password: guest
vhost: /
lazy: true
producers:
order_create:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
consumers:
order_create_1:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
queue_options: { name: 'order_create_1_qu' }
callback: application_frontend.consumer.order_create_1
order_create_2:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
queue_options: { name: 'order_create_2_qu' }
callback: application_frontend.consumer.order_create_2




2 Producer & 2 Exchange & 2 Queue & N Worker & 2 Consumer


If you had used only one shared exchange here, order "create" and "update" messages would have gone to both queues which would break the system. You must separate all components if you have different types of jobs which need to be handled by different consumers.


# You can run many workers like commands below.
$ app/console rabbitmq:consumer -m 100 order_create
$ app/console rabbitmq:consumer -m 100 order_create

$ app/console rabbitmq:consumer -m 100 order_update
$ app/console rabbitmq:consumer -m 100 order_update

old_sound_rabbit_mq:
connections:
default:
host: 127.0.0.1
port: 5672
user: guest
password: guest
vhost: /
lazy: true
producers:
order_create:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
order_update:
connection: default
exchange_options: { name: 'order_update_ex', type: fanout }
consumers:
order_create:
connection: default
exchange_options: { name: 'order_create_ex', type: fanout }
queue_options: { name: 'order_create_qu' }
callback: application_frontend.consumer.order_create
order_update:
connection: default
exchange_options: { name: 'order_update_ex', type: fanout }
queue_options: { name: 'order_update_qu' }
callback: application_frontend.consumer.order_update