symfony/messenger
Symfony Messenger helps PHP applications send and receive messages to and from other applications or message queues. It offers transports, middleware, and message handlers for building scalable, asynchronous, event-driven systems, and integrates smoothly with Symfony or standalone PHP projects.
Decoupling Microservices & Event-Driven Architecture:
Adopt Symfony Messenger to enable asynchronous communication between services (e.g., order processing, notifications, or analytics pipelines). Replace direct HTTP calls with message queues (RabbitMQ, Redis, Doctrine) to improve scalability and resilience.
Example: Replace synchronous UserService::sendEmail() with EmailSentEvent dispatched via Messenger, processed by a background worker.
Background Job Processing:
Offload CPU-intensive or time-consuming tasks (e.g., PDF generation, image resizing) to workers, improving frontend responsiveness.
Example: Use CommandBus to dispatch GenerateReportCommand and let workers handle it asynchronously.
Retry & Dead-Letter Queues (DLQ):
Implement retry logic for failed operations (e.g., payment processing) with configurable backoff strategies. Route persistent failures to a DLQ for manual review.
Example: Configure RetryStamp with exponential backoff for ProcessPaymentMessage.
Event Sourcing & CQRS:
Integrate with event stores (e.g., Doctrine transport) to persist domain events asynchronously, enabling replayability and audit logs.
Example: Dispatch OrderCreatedEvent to both a database and a Kafka topic via Messenger.
Security Posture & Patch Cadence (new): Messenger is now a security-sensitive dependency, not just plumbing. The v5.4.54 release is a [SECURITY] patch that hardens the message envelope against untrusted input:
X-Message-Stamp-* headers can inject into an envelope.
Product implication: treat the messaging layer as an attack surface (any producer writing to the queue can influence envelope metadata). This should appear as a standing line item in the security/upgrade backlog, and it strengthens the case for enabling message signing on any transport shared across trust boundaries.Build vs. Buy: Buy: Avoid reinventing message queues from scratch (e.g., custom RabbitMQ clients). Messenger provides battle-tested transports, serializers, middleware — and now a maintained security response process, which a hand-rolled consumer library will not have. Build: Only if you need proprietary features (e.g., custom protocol) not covered by supported transports (AMQP, Redis, Doctrine, etc.) — and only with an explicit plan for owning deserialization hardening yourself.
Roadmap Prioritization:
>= v5.4.54 on all branches; audit any custom Serializer, stamp classes, or header-based routing that assumes arbitrary stamps are accepted.aws/aws-sdk-php.SET commands).*"Symfony Messenger lets us modernize our backend by replacing slow, synchronous calls with fast, scalable message queues. This will:
X-Message-Stamp-* headers. We get that protection by upgrading, not by writing it ourselves.
It’s a drop-in solution for PHP teams—no need to reinvent queues or hire specialized DevOps for RabbitMQ setup."*"Symfony Messenger gives us:
messenger:consume) for local testing.laravel-queue).X-Message-Stamp-* headers can no longer put arbitrary stamps into an envelope.Action from this release: bump to >= v5.4.54, then check whether we rely on any of the now-restricted behaviour — custom stamps set via headers, consumers that unserialize envelopes from a shared queue, or middleware that re-dispatches decoded messages. Those paths may now fail closed, which is correct but needs a test pass.
Example migration path:
Bus for synchronous commands.AsyncTransport (Redis) for background jobs.RetryStamp and FailureTransport for resilience.*"Messenger integrates seamlessly with:
PrometheusBridge or custom middleware.phpunit/messenger and Dockerized transports.
Operational benefits:--sleep flag).v8.1.0-BETA3 tag is a separate, pre-release branch — do not conflate them). Schedule the upgrade during a normal maintenance window, roll workers first, and watch consumer logs for newly rejected/stripped stamps; a spike there means a producer is sending envelopes we previously accepted silently."*How can I help you explore Laravel packages today?