How to implement symfony messenger #513
-
Hi, I've been looking on this project issues and I found some answers but I think it would be a good Idea to document properly how to use Symfony Messenger using this template.
Here's my setup: # compose.prod.yml:
version: "3.4"
# Production environment override
services:
php: #...
messenger:
build:
context: .
target: frankenphp_prod_messenger
command: 'sh -c "php bin/console messenger:consume async scheduler_default -vv"'
environment:
DATABASE_URL: xxxx
MAILER_DSN: xxxx
restart: unless-stopped
depends_on:
- php
# Dockerfile
# all existing stuff ...
## Messenger
FROM frankenphp_prod AS frankenphp_prod_messenger
WORKDIR /app
HEALTHCHECK NONE
ENTRYPOINT ["docker-entrypoint"] # config/packages/messenger.yaml
framework:
messenger:
failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: 'doctrine://default?queue_name=failed'
sync: 'sync://'
routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: async
# other messages ...
#in dev env, we use sync transport to process messages immediately
when@dev:
framework:
messenger:
transports:
async: 'sync://' But according to the Symfony documentation, worker should not run forever and should be managed by supervisor or systemd What do you guys think ? How should we implements messenger in this template following the Symfony doc advices ? Thanks for the help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi tdumalin, You might consider using the php-worker:
build:
context: .
target: frankenphp_dev
image: ${IMAGES_PREFIX:-}app-php
restart: unless-stopped
command: php bin/console messenger:consume async -v --limit=10000 With this setup, the This approach avoids the need for external process control systems. |
Beta Was this translation helpful? Give feedback.
Hi tdumalin,
You might consider using the
--limit
option withmessenger:consume
:With this setup, the
restart: unless-stopped
Docker directive ensures that the container is automatically restarted after processing the specified number of messages.This approach avoids the need for external process control systems.
Please let me know what you think about it and how you solved this issue (which has been a while now).