Symfony Messenger

A message bus component for building async workflows, queues, and CQRS-style command handling.

Library
Composer
vv8.1.4
1,109stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
92/100Excellent
Development Activity96
Maintenance96
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture87
Code Quality88
Innovation83
Learning Curve75

Symfony Messenger is a message-bus component that helps applications send and receive messages, whether in-process (command/query/event handling) or across process boundaries via a message queue. It provides a routable MessageBus with a configurable middleware stack, so cross-cutting concerns like validation, logging, and transactions wrap message handling consistently.

Transports are pluggable — Doctrine DBAL, AMQP, Redis, and in-memory implementations ship with the component, with additional brokers (SQS, Beanstalkd, Kafka) available via bridge packages — letting the same application code run synchronously in development and asynchronously in production without changes to message or handler code.

What You Get

  • A MessageBus with a configurable, ordered middleware stack (validation, transaction, logging, etc.)
  • Message routing to one or more handlers based on message type
  • Pluggable transports: in-memory, Doctrine DBAL, AMQP, and Redis ship built-in, with bridges for SQS, Beanstalkd, and Kafka
  • Envelope/Stamp system for attaching metadata (delay, retry count, received timestamp) to messages without changing the message class
  • Built-in retry and failure-transport handling for messages that fail processing
  • A messenger:consume worker command for running async message consumers

Common Use Cases

  • Decoupling slow operations (emails, exports, webhooks) from the HTTP request/response cycle
  • Implementing CQRS-style command and query buses within a single application
  • Building event-driven workflows where one action triggers multiple independent side effects
  • Running background workers that consume from a queue and process jobs at controlled concurrency
  • Synchronously dispatching domain events in development while running them async in production, unchanged

Under The Hood

Architecture The component centers on MessageBus.php implementing MessageBusInterface, which dispatches an Envelope (wrapping the message plus Stamp metadata) through an ordered chain of Middleware/ classes before reaching a Handler. RoutableMessageBus.php and TraceableMessageBus.php add multi-bus routing and debug-collector support respectively. Transport/ defines the TransportInterface and ships InMemoryTransport, plus receiver/sender abstractions that bridge packages (Doctrine, AMQP, Redis) implement against. Worker.php drives the consume loop used by the messenger:consume console command in Command/. Tech Stack Requires PHP 8.4.1+, depends only on psr/log and symfony/clock in production, keeping the core dependency-light; DI wiring lives under DependencyInjection/ for Symfony’s service container, and a DataCollector/ integrates with the Symfony profiler for debugging message flow. Code Quality Tests/ mirrors the source tree closely (bus, middleware, transport, worker, retry-strategy tests) with 208 contributors maintaining it; as a core Symfony component it follows the framework’s shared CI and backward-compatibility promise across minor versions. API Design The #[AsMessageHandler] attribute (in Attribute/) lets handlers be plain classes with zero interface implementation, and the Envelope/Stamp pattern keeps transport-specific metadata (delay, redelivery count) out of domain message classes — a deliberate design choice that keeps message classes transport-agnostic and easy to unit test in isolation.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search