简体   繁体   English

Symfony Messenger 消费者池

[英]Symfony Messenger consumer pool

I'm not sure this is something possible: to have a pool of messenger consumers for the same queue ?我不确定这是否可能:为同一个队列拥有一个信使消费者池?

I've tried to use the Redis consumer= options but that's not it.我曾尝试使用 Redis consumer=选项,但事实并非如此。

Maybe a "pool" middleware could do some routing to specific transports?也许“池”中间件可以对特定传输进行一些路由?

Yes, you use multiple consumers for one queue.是的,您为一个队列使用多个消费者。 Symfony Messenger is designed to have multiple consumers. Symfony Messenger 旨在拥有多个消费者。 The example configuration from the Supervisor part of the documentation already has 2 instances:文档的 Supervisor 部分的示例配置已经有 2 个实例:

Supervisor configuration files typically live in a /etc/supervisor/conf.d directory. Supervisor 配置文件通常位于 /etc/supervisor/conf.d 目录中。 For example, you can create a new messenger-worker.conf file there to make sure that 2 instances of messenger:consume are running at all times:例如,您可以在那里创建一个新的 messenger-worker.conf 文件,以确保 2 个 messenger:consume 实例始终在运行:

(..) (..)

So you can just run bin/console messenger:consume async multiple times and in most cases, this will work without additional configuration.因此,您可以多次运行bin/console messenger:consume async并且在大多数情况下,这无需额外配置即可工作。 There is a warning about using the Redis Transport and multiple workers:有一个关于使用 Redis Transport 和多个 worker 的警告:

If you use the Redis Transport, note that each worker needs a unique consumer name to avoid the same message being handled by multiple workers.如果您使用 Redis 传输,请注意每个工作人员都需要一个唯一的消费者名称,以避免多个工作人员处理相同的消息。 One way to achieve this is to set an environment variable in the Supervisor configuration file, which you can then refer to in messenger.yaml (see Redis section above):实现此目的的一种方法是在 Supervisor 配置文件中设置一个环境变量,然后您可以在messenger.yaml引用该变量(请参阅上面的 Redis 部分):

environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM