enqueue/async-event-dispatcher
Symfony EventDispatcher extension that dispatches events asynchronously by sending them to a message queue, enabling background processing and improved responsiveness. Part of the Enqueue ecosystem; integrates with Symfony apps and supports MQ-driven event handling.
EventDispatcher with asynchronous message queues (e.g., RabbitMQ, Redis, Amazon SQS), aligning well with architectures requiring decoupled event processing (e.g., microservices, background jobs, or high-throughput systems).Event system (via Illuminate\Events\Dispatcher) is a drop-in replacement for Symfony’s EventDispatcher, making this package a natural fit for offloading event listeners to queues.EventDispatcher with AsyncEventDispatcher (via enqueue/async-event-dispatcher).queue:work or a dedicated worker process (e.g., Supervisor) to process async events.EventDispatcher binding in AppServiceProvider..env (e.g., QUEUE_CONNECTION=redis).JsonSerializable or use Illuminate\Contracts\Support\Arrayable).php-enqueue/amqp-ext or php-enqueue/redis for transport (adds ~10MB to deployment).enqueue/amqp-ext or enqueue/redis for queue drivers.| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Event Serialization | Non-serializable events (e.g., closures, resources) will fail silently. | Enforce JsonSerializable or Arrayable in event contracts. |
| Broker Dependency | Tight coupling to RabbitMQ/Redis; may require additional infrastructure. | Use Laravel’s QUEUE_CONNECTION to abstract the broker (e.g., switch to database). |
| Error Handling | Failed async events may go unnoticed (no built-in retry/dead-letter queue). | Implement a failed_jobs table or use Laravel’s ShouldQueue with retries. |
| Laravel Version | Last release in 2017; may not support Laravel 10+ features (e.g., PSR-15). | Fork or patch for compatibility; monitor for updates. |
| Testing Complexity | Async events require mocking queues/workers in unit tests. | Use Queue::fake() or Queue::assertPushed() for testing. |
Event system, queue:work, and ShouldQueue jobs.QUEUE_CONNECTION=redis).queue:work or custom workers (e.g., Supervisor).php-enqueue/amqp-ext), Redis (via php-enqueue/redis).EventDispatcher in a single module (e.g., notifications).Sent event for emails)..env.queue:work or Supervisor).| Component | Compatibility Notes |
|---|---|
| Laravel Events | Full compatibility; drop-in replacement for EventDispatcher. |
| Queue Drivers | Requires enqueue/amqp-ext or enqueue/redis (not native Laravel drivers). |
| Event Listeners | Must be serializable (e.g., no closures, resources). |
| Middleware | Async listeners cannot use Symfony middleware (not supported by this package). |
| Testing | Use Queue::fake() for unit tests; mock workers for integration tests. |
composer.json:
"require": {
"php-enqueue/async-event-dispatcher": "^1.0",
"php-enqueue/redis": "^0.10" // or "php-enqueue/amqp-ext"
}
AsyncEventDispatcher in AppServiceProvider:
use Enqueue\AsyncEventDispatcher\AsyncEventDispatcher;
use Enqueue\Client\Producer;
public function register()
{
$producer = new Producer(new \Enqueue\Redis\RedisConnection());
$this->app->bind(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class,
function () use ($producer) {
return new AsyncEventDispatcher($producer, new \Symfony\Component\EventDispatcher\EventDispatcher());
});
}
@Async (if supported) or ensure they’re serializable.class SendNotificationListener implements ShouldQueue
{
public function handle(ExampleEvent $event)
{
// Async processing
}
}
php artisan queue:work --queue=events
[program:laravel-worker]
command=php artisan queue:work --queue=events
numprocs=8
queue:failed-table for visibility into failed jobs.failed_jobs table.queue:failed-table).QUEUE_CONNECTION=sync for local debugging.queue:work processes or containers.How can I help you explore Laravel packages today?