symfony/doctrine-messenger
Doctrine integration for Symfony Messenger. Store, dispatch, and consume messages using Doctrine-backed transports and tooling. Part of the Symfony ecosystem; issues and contributions go through the main Symfony repository.
This package is a Symfony-specific bridge and does not integrate with Laravel. It provides Doctrine DBAL integration for Symfony Messenger, enabling persistent message transport using database tables. To start with Symfony:
composer require symfony/doctrine-messengerconfig/packages/messenger.yaml:
framework:
messenger:
transports:
async: 'doctrine://default'
php bin/console messenger:setup-db
The first use case is reliably queuing background jobs (e.g., sending emails, generating reports) without external infrastructure like RabbitMQ — ideal for environments already using Doctrine.
Queue separation: Use the queue_name DSN option to route messages to different logical queues in one table:
transports:
notifications: 'doctrine://default?queue_name=notifications'
exports: 'doctrine://default?queue_name=exports'
Consumer orchestration: Run dedicated workers per queue:
php bin/console messenger:consume notifications --single-message
php bin/console messenger:consume exports --time-limit=1800
Retry & failure handling: Configure failure transport and middleware:
framework:
messenger:
failure_transport: failed
transports:
async: 'doctrine://default?queue_name=async'
failed: 'doctrine://default?queue_name=failed'
routing:
'App\Message\MyMessage': async
Then consume the failed transport separately with messenger:consume failed.
Custom transport options: Override table/column names and use custom Doctrine connection:
transports:
custom_async: 'doctrine://custom_connection?table=messaging&queue_column=channel'
Observability: Create raw Doctrine queries to monitor stuck messages (e.g., SELECT COUNT(*) WHERE scheduled_at < ? AND handled_at IS NULL).
v6.4.31+, v7.3.9+, or v8.0.3+ — older versions used SELECT FOR UPDATE that caused deadlocks. Use --memory-limit=128M in workers to reduce transaction contention.NOTIFY behavior: With DBAL v4+, the transport now uses pg_notify() explicitly. Avoid defining triggers on the table — they’re obsolete and cause errors. Check v7.4.1+, v8.0.1+ for fixes to PHP 8.5 deprecation.messenger:setup-db now handles duplicate sequences/triggers — avoid manual DDL. Use lowercase column mappings.queue_name, body, headers).messenger:setup-db --force and verify the schema via doctrine:schema:validate.UNLISTEN calls: Fixed in v8.0.5/v6.4.33/v7.4.5. If PostgreSQL consumers disconnect unexpectedly, check your version.__serialize()/__unserialize() — __sleep()/__wakeup() were removed in PHP 8.1+ behavior and fixed in v6.4.26/v7.3.4+.How can I help you explore Laravel packages today?