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.
For Laravel developers, this package is not directly applicable—it is a Symfony-specific bridge. However, if you're working in a Symfony/Laravel hybrid or need a Doctrine-backed message transport, here’s how to approach it:
composer require symfony/doctrine-messenger
config/packages/messenger.yaml:
framework:
messenger:
transports:
doctrine_transport: 'doctrine://default'
routing:
'App\Message\YourMessage': doctrine_transport
php bin/console doctrine:messenger:setup-transport
use Symfony\Component\Messenger\MessageBusInterface;
public function __construct(private MessageBusInterface $bus) {}
public function sendMessage(): void
{
$this->bus->dispatch(new YourMessage());
}
If you must use Doctrine in Laravel (e.g., for legacy systems), you could:
symfony/messenger + symfony/doctrine-messenger in a Symfony microkernel alongside Laravel.// app/Providers/SymfonyMessengerServiceProvider.php
public function register()
{
$this->app->singleton(MessageBusInterface::class, function ($app) {
return require __DIR__.'/../../vendor/symfony/messenger/MessageBus.php';
});
}
queue_name to partition messages:
transports:
orders: 'doctrine://default?queue_name=orders'
notifications: 'doctrine://default?queue_name=notifications'
framework:
messenger:
transports:
async: 'doctrine://default'
middleware:
- 'doctrine://default?retry_strategy=exponential'
php bin/console messenger:consume orders --limit=10 --time-limit=300
--limit to control message throughput:
php bin/console messenger:consume notifications --limit=50
If bridging Symfony Messenger to Laravel:
MessageBus as a Laravel service (see Getting Started).jobs) and Symfony’s (messenger_message) don’t conflict.MessageSentToTransportEvent):
use Symfony\Component\Messenger\Event\SentToTransportEvent;
$bus->dispatch(new YourMessage(), [new SentToTransportEventListener()]);
Database Locking:
locked_at column). Long-running consumers may cause deadlocks.--time-limit to avoid holding locks too long.Schema Mismatches:
jobs table and Symfony’s messenger_message table cannot coexist without conflicts.symfony_messenger_message).Transaction Isolation:
REPEATABLE READ may cause issues.isolation_level=serializable in your DBAL connection.PostgreSQL-Specific Quirks:
LISTEN/NOTIFY for real-time consumption. If using connection pooling, ensure the pool reuses the same backend PID.pgsql.notification_queue_size or use pg_notify() explicitly.PHP 8.5+ Deprecations:
pgsql_get_notify() is deprecated. Symfony 8.1+ uses pg_notify() instead.php bin/console messenger:failed-messages-list
php bin/console messenger:consume doctrine_transport --debug
doctrine:
dbal:
logging: true
profiling: true
SELECT * FROM messenger_message WHERE locked_at IS NOT NULL to find stuck messages.DoctrineTransport to add features (e.g., priority queues):
class PriorityDoctrineTransport extends DoctrineTransport
{
protected function getMessageTable(): string
{
return 'priority_messenger_message';
}
}
framework:
messenger:
middleware:
- 'App\Middleware\LogMessageMiddleware'
DoctrineTransportFactory:
$factory = new DoctrineTransportFactory();
$factory->setSchema([
'message' => 'custom_messenger_message',
'failed_message' => 'custom_messenger_failed_message',
]);
EventDispatcher and Laravel’s Dispatcher will clash. Use a proxy pattern to bridge them.messenger:consume cannot replace Laravel’s queue:work. Run them in parallel or migrate entirely.ShouldQueue traits, ensure they’re serializable.batch_size).message_id, queue_name, and locked_at for large queues.pgsql.persistent to avoid reconnect overhead.How can I help you explore Laravel packages today?