Eğer symfony uygulamanızda RabbitMqBundle kullanıyorsanız, aşağıdaki RabbitMQ fanout exchange konfigürasyonlar işinize yarayabilir. Eğer konfigürasyonunuz içinde birden fazla consumer kullanıyorsanız, size multiple_consumers konfigürasyon seçeneğini kullanmanızı tavsiye ederim. Bir tane örnek yazım var ama arayıp bulmanız lazım.


Fanout gerçekleri



Hatırlatıcı


Sisteminizde queue/exchange konfigürasyonlarını yarattığınız veya yenilediğiniz zaman, rabbitmq sunucusuna yenilikler ve değişikliklerle ilgili haber vermek için $ bin/console rabbitmq:setup-fabric komutunu her zaman çalıştırmanız gerekir. Aksi taktirde yayınlanan mesajların işlenmeme durumu oluşabilir.


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


Tüm order "create" mesajları, tek bir sıraya giderler.


# 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


Eğer bir mesajı iki ayrı şekilde, iki ayrı consumer tarafından işlemek isterseniz, aşağıdaki ayarları kullanabilirsiniz. Bu örnekte bir mesajın kopyası, iki ayrı sıraya gider.


# 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


Bu örnekte eğer sadece bir tane ortak exchange kullanmış olsaydınız, order "create" ve "update" mesajları her iki sırayada giderlerdi ki bu da sistemi bozardı. Eğer mesajlar farklı şekillerde işleneceklerse, tüm bileşenleri birbirlerinden ayırmanız gerekir.


# 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