symfony-messenger,使用apachekafka作为队列传输

9rygscc1  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(610)

我不知道如何配置 Kafka 为了 Symfony messenger . 一切都很好 rabbitmq (我创建了messenger和messenger处理程序):
.环境:

MESSENGER_TRANSPORT_DSN=amqp://user:password@myhost:5672/%2f/messages

配置/packages/messenger.yaml

framework:
  messenger:
    transports:
      async: "%env(MESSENGER_TRANSPORT_DSN)%"

.环境

MESSENGER_TRANSPORT_DSN=enqueue://node-1.kafka.myhost.com:9092/%2f/messages

配置/packages/messenger.yaml

framework:
  messenger:
    transports:
      async: "%env(MESSENGER_TRANSPORT_DSN)%"

请给我举个最好的例子。谢谢!

8fq7wneg

8fq7wneg1#

我的发展:docker+centos 7+php73,nginx。
此配置的解决方案:
1安装php rdkafka(重要提示:版本3.1.x!,将路径更改为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将php扩展添加到php.ini

[rdkafka]
extension=rdkafka.so

三。symfony安装包:

composer req symfony/messenger enqueue/rdkafka enqueue/enqueue-bundle sroze/messenger-enqueue-transport enqueue/async-event-dispatcher

4注册bundles-添加到config/bundles.php

Enqueue\Bundle\EnqueueBundle::class => ['all' => true],
Enqueue\MessengerAdapter\Bundle\EnqueueAdapterBundle::class => ['all' => true],

5添加文件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添加文件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': asyn

7添加到.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来自docu的messege和messengehandlementation:httpshttp://symfony.com/doc/current/messenger.html
9运行使用者:

php bin/console messenger:consume async

祝你好运!

相关问题