14/02/2016 - RABBITMQ, SYMFONY
Eğer konfigürasyonunuz içinde birden fazla consumer kullanıyorsanız, size multiple_consumers konfigürasyon seçeneğini kullanmanızı tavsiye ederim.
old_sound_rabbit_mq:
connections:
.....
producers:
order_create_bmw:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_bmw_qu
routing_keys:
- bmw
order_create_audi_mercedes:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_audi_mercedes_qu
routing_keys:
- audi
- mercedes
consumers:
order_create_bmw:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_bmw_qu
routing_keys:
- bmw
callback: application_frontend.consumer.order_create_bmw
order_create_audi_mercedes:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_audi_mercedes_qu
routing_keys:
- audi
- mercedes
callback: application_frontend.consumer.order_create_audi_mercedes
Tekli consumerleri aşağıdaki gibi çalıştırırız.
# Consumes only bmw messges
$ app/console rabbitmq:consumer -m 100 order_create_bmw
$ app/console rabbitmq:consumer -m 100 order_create_bmw
# Consumes only audi and mercedes messges
$ app/console rabbitmq:consumer -m 100 order_create_audi_mercedes
$ app/console rabbitmq:consumer -m 100 order_create_audi_mercedes
old_sound_rabbit_mq:
connections:
.....
producers:
order_create_bmw:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_bmw_qu
routing_keys:
- bmw
order_create_audi_mercedes:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queue_options:
name: order_create_audi_mercedes_qu
routing_keys:
- audi
- mercedes
multiple_consumers:
order:
connection: default
exchange_options: { name: order_create_ex, type: direct }
queues:
order_create_bmw:
name: order_create_bmw_qu
callback: application_frontend.consumer.order_create_bmw
routing_keys:
- bmw
order_create_audi_mercedes:
name: order_create_audi_mercedes_qu
callback: application_frontend.consumer.order_create_audi_mercedes
routing_keys:
- audi
- mercedes
Aşağıda da gördüğümüz gibi, "bmw" ve "audi/mercedes" mesajları için ayrı ayrı consumer çalıştırmamıza gerek yok.
# Consumes all "bmw", "audi" and "mercedes" messages
$ app/console rabbitmq:multiple-consumer -m 100 order
$ app/console rabbitmq:multiple-consumer -m 100 order