RabbitMqBundle
Symfony bundle integrating php-amqplib for RabbitMQ producers, consumers, and console commands
Repository Health
Technical Analysis
RabbitMqBundle wires php-amqplib/php-amqplib into the Symfony framework, letting applications declare RabbitMQ producers, consumers, and RPC clients directly in Symfony’s DI configuration instead of wiring AMQP connections by hand. It ships console commands (rabbitmq:consumer, rabbitmq:setup-fabric, rabbitmq:stdin-producer, etc.) for running consumers as long-lived workers, purging queues, and declaring exchange/queue topology.
Originally known as oldsound/rabbitmq-bundle, the project supports multiple consumer patterns — basic, batch, multiple-queue, dynamic, and anonymous consumers — plus a Symfony profiler data collector for inspecting AMQP activity during development, making it a common choice for Symfony applications building queue-driven, asynchronous workflows on top of RabbitMQ.
What You Get
- DI-configurable producers, consumers, and RPC clients backed by
php-amqplib/php-amqplib - Console commands for running consumers (
rabbitmq:consumer), setting up exchange/queue topology (rabbitmq:setup-fabric), and purging queues - Multiple consumer strategies: basic, batch, multiple-queue, dynamic, and anonymous consumers
- A Symfony profiler DataCollector for inspecting AMQP messages during local development
- Event dispatching around message consumption for custom hooks
Common Use Cases
- Running long-lived background workers that consume jobs from RabbitMQ queues in a Symfony app
- Publishing domain events or async jobs from application code to RabbitMQ exchanges
- Declaring RabbitMQ exchange/queue/binding topology declaratively via Symfony configuration
- Building RPC-style request/response messaging over AMQP between Symfony services
Under The Hood
Architecture
The bundle’s RabbitMq/ directory contains the core runtime classes — BaseAmqp (shared connection/channel handling), Producer/Consumer and their variants (BatchConsumer, MultipleConsumer, DynamicConsumer, AnonConsumer), and RpcClient — each built on AMQPConnectionFactory for connection management. Symfony’s DependencyInjection extension parses bundle configuration into service definitions for these classes, while Command/ exposes each consumer/producer type as a console command (extending BaseRabbitMqCommand) so operators can run them as standalone processes.
Tech Stack
PHP 8.2+ built directly on php-amqplib/php-amqplib for the AMQP protocol implementation, integrating with Symfony’s dependency-injection, event-dispatcher, config, console, and http-kernel components (6.x/7.x/8.x). Tests use Pest (PHP testing framework) alongside PHPStan for static analysis.
Code Quality
The Tests/ directory contains 25 test files covering consumers, producers, and command behavior, and the project uses PHPStan for static analysis. The codebase cleanly separates runtime messaging classes (RabbitMq/) from Symfony wiring (DependencyInjection/) and CLI entry points (Command/), consistent with its long history as a widely-used Symfony bundle (formerly oldsound/rabbitmq-bundle).
API Design Consumers, producers, and RPC clients are declared in Symfony configuration (YAML/PHP) and then simply referenced by service ID or run via console commands, which keeps day-to-day usage declarative; however, the range of consumer types (basic, batch, multiple, dynamic, anonymous) means understanding which pattern fits a given workload takes some upfront reading of the README.