我正在尝试使用 Symfony Messenger 组件使用具有相同 Redis 传输的多个消费者。正如 Symfony 指南中提到的,如果我们对流/组/信使使用相同的值,我们可能会遇到问题,因为相同的消息可以被多个消费者处理。所以我更新了我的主管配置如下:
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d
然后,我更新了我的 messenger.yaml 文件,如下所示:
redis:
dsn: '%env(MESSENGER_TRANSPORT_REDIS)%'
options:
consumer: '%env(MESSENGER_CONSUMER_NAME)%'
我已经重新加载了主管:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start messenger-consume:*
但我仍然收到错误:
[2021-12-25T18:33:08.954217+01:00] console.CRITICAL: Error thrown while running command "messenger-dispatcher --count=100". Message: "Environment variable not found: "MESSENGER_CONSUMER_NAME"." {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exception\\EnvNotFoundException(code: 0): Environment variable not found: \"MESSENGER_CONSUMER_NAME\". at /var/www/vendor/symfony/dependency-injection/EnvVarProcessor.php:172)","command":"messenger-dispatcher --count=100","message":"Environment variable not found: \"MESSENGER_CONSUMER_NAME\"."} []
我遵循了指导方针,但某处缺少一些东西……但是在哪里?为什么我的应用程序不读取 env var?
如果我打电话给我的消费者:
MESSENGER_CONSUMER_NAME=myconsumer ./bin/console messenger:consume redis
它按预期工作;它不仅适用于主管 var。
提前致谢
更新这是我的主管文件的完整部分配置:
[program:consumer-redis]
command=php /var/www/bin/console messenger:consume redis --limit=5 --time-limit=3600
user=root
numprocs=6
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d