Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Messenger Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • 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:

    • Rejects decoded messages carrying non-sendable stamps.
    • Validates stamps of unserialized envelopes before dispatch to handlers.
    • Restricts what 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:

    • Phase 0 (immediate): Pin and upgrade to >= v5.4.54 on all branches; audit any custom Serializer, stamp classes, or header-based routing that assumes arbitrary stamps are accepted.
    • Phase 1: Replace synchronous calls with Messenger for critical paths (e.g., notifications).
    • Phase 2: Add retry/DLQ for fault tolerance, plus message signing for any cross-team or externally-adjacent transport.
    • Phase 3: Extend to event sourcing or multi-tenant messaging.

When to Consider This Package

Adopt Symfony Messenger If:

  • Your system uses PHP/Laravel/Symfony and needs asynchronous messaging (queues, events, commands).
  • You require multi-transport support (AMQP, Redis, Doctrine, etc.) without vendor lock-in.
  • You need retry mechanisms, DLQs, or message signing (security) out of the box.
  • Your team prefers declarative configuration (YAML/XML/PHP) over low-level SDKs (e.g., raw RabbitMQ).
  • You’re building scalable microservices or event-driven architectures with PHP.
  • You want a dependency with an active security release process — patch releases for envelope/deserialization hardening land on maintained branches (e.g., v5.4.x) and are worth tracking as part of routine dependency hygiene.

Look Elsewhere If:

  • You’re not using PHP (e.g., Node.js, Go, Python). Consider alternatives like:
    • Node.js: BullMQ, RabbitMQ client.
    • Python: Celery, RQ.
    • Java: Spring AMQP, Kafka.
  • You need real-time pub/sub (WebSockets). Pair Messenger with Mercure or Pusher.
  • You require serverless integration (e.g., AWS SQS). Use AWS SDK directly or a wrapper like aws/aws-sdk-php.
  • Your team lacks PHP/Symfony expertise. The learning curve for transports/middleware may be steep.
  • You need exactly-once processing guarantees. Messenger’s idempotency relies on transport-specific deduplication (e.g., Redis SET commands).
  • You cannot patch on a regular cadence or run an unsupported/abandoned branch. Since envelope deserialization is a security boundary, staying on an unpatched minor version is a real risk, not a paperwork issue.

How to Pitch It (Stakeholders)

For Executives:

*"Symfony Messenger lets us modernize our backend by replacing slow, synchronous calls with fast, scalable message queues. This will:

  • Reduce latency for users by offloading heavy tasks (e.g., reports, emails) to background workers.
  • Improve reliability with automatic retries and dead-letter queues for failed jobs.
  • Cut costs by scaling workers dynamically (e.g., Kubernetes pods) instead of over-provisioning servers.
  • Future-proof our architecture for microservices or event-driven workflows (e.g., real-time notifications).
  • Reduce security exposure: the maintainers ship targeted security patches for message handling — the latest hardens envelopes against tampered stamps and injected 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."

For Engineers:

*"Symfony Messenger gives us:

  • Transport agnosticism: Swap between Redis, AMQP, or Doctrine without changing business logic.
  • Middleware pipeline: Add logging, metrics (Prometheus), or security (message signing) via reusable components.
  • Developer experience: Type-safe message classes, auto-wiring, and CLI tools (messenger:consume) for local testing.
  • Battle-tested: Used in production by Symfony, Drupal, and Laravel (via laravel-queue).
  • Hardened envelope handling (v5.4.54): decoded messages with non-sendable stamps are rejected, unserialized envelopes have their stamps validated, and 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:

  1. Start with Bus for synchronous commands.
  2. Add AsyncTransport (Redis) for background jobs.
  3. Introduce RetryStamp and FailureTransport for resilience.
  4. Enable message signing wherever producers aren't fully trusted. No lock-in: If we need Kafka later, we can replace the transport layer."*

For DevOps/SRE:

*"Messenger integrates seamlessly with:

  • Kubernetes: Deploy workers as stateless pods with horizontal scaling.
  • Monitoring: Export metrics via PrometheusBridge or custom middleware.
  • CI/CD: Test message flows with phpunit/messenger and Dockerized transports. Operational benefits:
  • No single point of failure: Workers are disposable; messages persist in the queue.
  • Resource efficiency: Workers sleep when idle (--sleep flag).
  • Security: Sign messages per handler to prevent tampering. Patch advisory: v5.4.54 is a security release on the 5.4 line (the tracker's 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."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc