Download the PHP package rabbitevents/symfony-bundle without Composer
On this page you can find all versions of the php package rabbitevents/symfony-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rabbitevents/symfony-bundle
More information about rabbitevents/symfony-bundle
Files in rabbitevents/symfony-bundle
Package symfony-bundle
Short Description RabbitEvents for Symfony โ publish and listen to events across microservices via RabbitMQ
License MIT
Informations about the package symfony-bundle
RabbitEvents Symfony Bundle
Publish and listen to events across microservices via RabbitMQ โ for Symfony.
This bundle provides inter-application event communication using RabbitMQ topic exchanges. Events published by any microservice are routed across services based on routing keys, with full support for wildcard routing.
Features
- ๐ท๏ธ Modern PHP 8+ Attributes: Register listeners via
#[AsRabbitListener], on whole classes or individual methods. - โก Zero-Overhead Publisher: Lazy connection initialization โ RabbitMQ connections are only established when messages are published.
- ๐ Wildcard Routing: Full AMQP topic routing key support (
*and#). - ๐ฆ Pluggable Serialization: Built-in JSON serializer, optional Protobuf serializer, or custom serializers via Symfony DI tags.
- ๐ Resilience & Retries: Built-in retry handling (
--tries,--sleep), dead-letter support, andfailed()listener callbacks. - ๐งช Testing Support:
PublishableEventTestingtrait for asserting event publication without a live RabbitMQ broker. - ๐ Modern PHP & Symfony: Compatible with PHP 8.2+ and Symfony 6.4, 7.x, and 8.x.
Table of Contents
- Installation
- Quick Start
- Publishing Events
- 1. Event Classes (
AbstractPublishableEvent) - 2. Publishing via Dependency Injection
- 3. Implementing
ShouldPublishDirectly
- 1. Event Classes (
- Listening for Events
- Class-Level Listener Attribute
- Method-Level Listener Attributes
- Wildcard Listeners
- Failure Handling (
failed()callback)
- Console Commands
rabbitevents:listenrabbitevents:list
- Configuration
- Serialization
- JSON (Default)
- Protobuf Support
- Custom Serializers
- Testing
- Examples
- License
Installation
Install the bundle via Composer:
If you don't use Symfony Flex, enable the bundle in config/bundles.php:
Quick Start
1. Configure Connection
Create config/packages/rabbitevents.yaml:
Add environment variables to your .env:
2. Create and Publish an Event
3. Create a Listener
4. Start Listening
Publishing Events
1. Event Classes (AbstractPublishableEvent)
Extending AbstractPublishableEvent gives your event a static-style $event->publish() helper:
2. Publishing via Dependency Injection
For clean architecture and easier unit testing, inject RabbitEvents\Bundle\Publisher directly into your services:
3. Implementing ShouldPublish Directly
If you prefer not to extend AbstractPublishableEvent, implement ShouldPublish:
Listening for Events
Listeners are automatically discovered and registered via the #[AsRabbitListener] attribute.
Class-Level Listener Attribute
Place #[AsRabbitListener] on the class. The handle() method (or __invoke()) will be called when the event arrives:
Method-Level Listener Attributes
You can group multiple event handlers in a single service class by annotating individual methods:
Wildcard Listeners
RabbitEvents uses RabbitMQ topic exchanges, supporting wildcard matching in routing keys:
*(asterisk) matches exactly one word:order.*matchesorder.created,order.cancelled.#(hash) matches zero or more words:order.#matchesorder.created,order.item.added.
Failure Handling (failed() callback)
If an exception occurs during processing and retry attempts are exhausted, the worker calls the failed(\Throwable $e) method on your listener:
Console Commands
rabbitevents:listen
Start a background worker to consume events from RabbitMQ:
Available Options
| Option | Description | Default |
|---|---|---|
--service, -s |
Service name used to isolate queue names per service | app |
--memory |
Memory limit in MB before worker gracefully restarts | 128 |
--timeout |
Max processing timeout in seconds per message | 60 |
--tries |
Max retry attempts for failed messages | 0 (no retries) |
--sleep |
Sleep delay in seconds between retries | 1 |
rabbitevents:list
List all discovered RabbitEvents listeners and their routing keys:
Configuration
Full options reference for config/packages/rabbitevents.yaml:
Serialization
JSON (Default)
The default serializer encodes arrays and objects as JSON and decodes them to associative arrays in your listener's handle(array $payload) method.
Protobuf Support
If google/protobuf is installed in your project, the Protobuf serializer is automatically registered:
Custom Serializers
To register a custom serializer, implement RabbitEvents\Bundle\Contract\Serializer and tag it:
Testing
Use the PublishableEventTesting trait in PHPUnit tests to fake event publication without connecting to RabbitMQ:
Examples
Check the examples/ directory for complete, ready-to-use examples:
OrderCreatedEvent.phpโ Standard publishable event.UserRegisteredEvent.phpโ Event usingShouldPublishand DI injection.OrderCreatedListener.phpโ Class-level#[AsRabbitListener].OrderLifecycleListener.phpโ Multi-method#[AsRabbitListener].UserWildcardListener.phpโ Wildcarduser.*pattern matching.PaymentProcessedListener.phpโ Custom error and failure handling (failed()).
License
This package is open-sourced software licensed under the MIT license.
All versions of symfony-bundle with dependencies
ext-json Version *
enqueue/amqp-lib Version ^0.10
psr/log Version ^3.0
symfony/config Version ^7.0|^8.0
symfony/console Version ^7.0|^8.0
symfony/dependency-injection Version ^7.0|^8.0
symfony/event-dispatcher Version ^7.0|^8.0
symfony/framework-bundle Version ^7.0|^8.0