This Symfony bundle provides a PDO-based transport for the Symfony Messenger component. It serves as a lightweight alternative to the official Doctrine transport, specifically designed for projects that do not use Doctrine ORM or DBAL but still require a reliable database-backed message queue.
Add the bundle to your config/bundles.php:
return [
// ...
Tdc\PdoMessengerTransport\TdcPdoMessengerTransport::class => ['all' => true],
];Execute the following Query to create the database table:
CREATE TABLE messenger_messages (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
body LONGTEXT NOT NULL,
headers LONGTEXT NOT NULL,
queue_name VARCHAR(190) NOT NULL,
available_at DATETIME NOT NULL,
delivered_at DATETIME DEFAULT NULL,
created_at DATETIME NOT NULL
);The bundle requires a \PDO instance to be registered in your service container. You can define a new PDO service or use an existing one (e.g., from Doctrine):
# config/services.yaml
services:
# Option A: Create a new PDO service
PDO:
class: PDO
arguments:
- "mysql:host=%env(DB_HOST)%;dbname=%env(DB_NAME)%"
- "%env(DB_USER)%"
- "%env(DB_PASSWORD)%"
# Option B: Use Doctrine's connection
# PDO:
# class: PDO
# factory: ['@database_connection', 'getNativeConnection']Create config/packages/tdc_pdo_messenger_transport.yaml:
tdc_pdo_messenger_transport:
pdo_service: 'PDO' # The ID of your PDO service (from step 1)
table_name: 'messenger_messages' # optional, default: messenger_messagesIf you don't provide a pdo_service, the bundle will try to autowire a \PDO instance.
In your messenger configuration, use the pdoqueue:// DSN.
# config/packages/messenger.yaml
framework:
messenger:
transports:
async: 'pdoqueue://default'Run the messenger worker as usual:
php bin/console messenger:consume async