cedricziel/symfony-messenger-pubsub-bundle
Install the Bundle
composer require cedricziel/symfony-messenger-pubsub-bundle
Configure Messenger Transport
Add the DSN to your .env:
MESSENGER_TRANSPORT_DSN=pubsub://your-project-id/your-topic?subscription=your-subscription
Ensure your config/packages/messenger.yaml includes the transport:
framework:
messenger:
transports:
pubsub: '%env(MESSENGER_TRANSPORT_DSN)%'
First Use Case: Send a Message Dispatch a message via CLI:
php bin/console messenger:send MyMessageClass
Verify the message appears in your Pub/Sub topic.
gcloud pubsub topics list to validate topic/subscription names.Push vs. Pull
routes.xml (auto-generated by the bundle). Useful for real-time processing.
# config/routes.yaml
_pubsub_push:
resource: '@GoogleCloudPubSubMessengerBundle/Resources/config/routes.xml'
MESSENGER_TRANSPORT_DSN). Use for batch processing.Message Handling
Symfony\Component\Messenger\Message or use DTOs.
class MyMessage implements MessageInterface {
public string $content;
}
config/packages/messenger.yaml:
framework:
messenger:
handlers:
my_handler:
type: MyMessage
handler: App\MessageHandler\MyHandler
Retry Logic Leverage Symfony’s retry strategy for transient failures:
transports:
pubsub:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
retry_strategy:
max_retries: 3
delay: 1000
pubsub.publisher and pubsub.subscriber roles.pubsub://project-dev/topic).DSN Format
pubsub://project/topic?subscription=sub is required. Omitting subscription causes silent failures.php bin/console debug:messenger to validate transport configuration.Push Endpoint
_pubsub_push routes to avoid clashes with existing routes.Message Size Limits
APP_DEBUG=1) to see transport errors.php bin/console messenger:consume pubsub -vv
Custom Middleware Add middleware to transform messages before sending:
framework:
messenger:
transports:
pubsub:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
middleware:
- App\Middleware\PubSubSerializer
Async Processing Use Symfony’s async workers for high-throughput topics:
php bin/console messenger:consume pubsub -w --limit=100
Event Listeners
Hook into MESSENGER_MESSAGE_SENT/MESSENGER_MESSAGE_FAILED events for auditing:
// config/services.yaml
App\EventListener\PubSubLogger:
tags:
- { name: kernel.event_listener, event: MESSENGER_MESSAGE_SENT, method: onMessageSent }
How can I help you explore Laravel packages today?