I don't know how to configure Kafka
for Symfony messenger
. Everything works for rabbitmq
(I created messenger and messenger handler):
.env:
MESSENGER_TRANSPORT_DSN=amqp://user:password@myhost:5672/%2f/messages
config/packages/messenger.yaml
framework:
messenger:
transports:
async: "%env(MESSENGER_TRANSPORT_DSN)%"
.env
MESSENGER_TRANSPORT_DSN=enqueue://node-1.kafka.myhost.com:9092/%2f/messages
config/packages/messenger.yaml
framework:
messenger:
transports:
async: "%env(MESSENGER_TRANSPORT_DSN)%"
Please, give me the best example. Thanks!
My develompent: Docker + Centos 7 + PHP73, NGINX.
Solution for this configuration:
1. Install php-rdkafka (important: version 3.1.x!, change path to php ;))
yum -y install make librdkafka-devel && git clone --branch 3.1.x https://github.com/arnaud-lb/php-rdkafka.git && cd php-rdkafka && /path/to/php73/root/bin/phpize && ./configure --with-php-config=/path/to/php73/root/bin/php-config && make all -j 5 && make install
2. Add php extension to php.ini
[rdkafka]
extension=rdkafka.so
3. Install package for symfony:
composer req symfony/messenger enqueue/rdkafka enqueue/enqueue-bundle sroze/messenger-enqueue-transport enqueue/async-event-dispatcher
4. Register bundles - add to config/bundles.php
Enqueue\Bundle\EnqueueBundle::class => ['all' => true],
Enqueue\MessengerAdapter\Bundle\EnqueueAdapterBundle::class => ['all' => true],
5. add file config/packages/enqueue.yaml:
enqueue:
default:
transport:
dsn: "rdkafka://"
global:
group.id: 'myapp'
metadata.broker.list: "%env(KAFKA_BROKER_LIST)%"
topic:
auto.offset.reset: beginning
commit_async: true
client: ~
6. add file config/packages/messenger.yaml:
framework:
messenger:
failure_transport: failed
transports:
async:
dsn: "%env(MESSENGER_TRANSPORT_DSN)%"
failed:
dsn: "doctrine://default?queue_name=failed"
routing:
'App\Message\EmailNotification': async
7. add to .env:
###> messenger ###
MESSENGER_TRANSPORT_DSN=enqueue://default?topic[name]=messages&queue[name]=messages
KAFKA_BROKER_LIST=node-1.kafka.host:9092,node-2.kafka.host:9092,node-3.kafka.host:9092
###< messenger ###
8. Message and MessageHandler from documentation: https://symfony.com/doc/current/messenger.html
9. Run consumer:
php bin/console messenger:consume async
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With