- How do I install AsyncEventDispatcher in a Laravel project?
- Add the package via Composer with `composer require bodaclick/async-event-dispatcher:1.0.x-dev`. Register the dispatcher in your `AppServiceProvider` as a singleton, then bind it to replace Laravel’s default event dispatcher where needed.
- Can I use this package with Laravel’s built-in event system?
- Yes, it’s designed as a drop-in replacement. Swap `Event::dispatch()` with `$asyncDispatcher->dispatch()` for async behavior. Existing events must implement `AsyncEventInterface` for compatibility.
- What are the supported Laravel and PHP versions?
- The package supports PHP 7.4–8.1 and is compatible with Laravel 8–9. For Laravel 10+, check for breaking changes in the RabbitMQ or Symfony dependencies, as the package is no longer actively maintained.
- How do I configure RabbitMQ for async event dispatching?
- Initialize the `RabbitMQDriver` with your connection details (host, port, credentials) and register it with the dispatcher. Example: `$driver = new RabbitMQDriver(['host' => 'localhost']); $ed->addDriver($driver, 'event.name');`
- Is the file driver suitable for production use?
- No, the file driver is only for development or testing. It lacks reliability guarantees (race conditions, disk I/O bottlenecks) and isn’t designed for production workloads.
- How do I handle failed async events (e.g., RabbitMQ connection issues)?
- The package doesn’t include retry logic or dead-letter queues. Wrap the dispatcher in a custom retry mechanism or use Laravel’s queue system alongside it for error handling.
- Can I create a custom driver (e.g., for Redis or Kafka)?
- Yes, implement the `AsyncEventDriverInterface` and register it with the dispatcher. Example: `$driver = new RedisDriver(); $ed->addDriver($driver, 'event.name');`
- What’s the performance impact of async event dispatching?
- Async dispatching reduces request latency by offloading work to background processes (RabbitMQ). Throughput depends on your driver (e.g., RabbitMQ can handle thousands of events/sec), but test under load for your specific use case.
- How do I migrate from synchronous to async events in Laravel?
- Start with non-critical events (e.g., `UserRegistered`). Implement `AsyncEventInterface`, register the dispatcher, and gradually replace `Event::dispatch()` calls. Use feature flags to parallelize sync/async dispatch during migration.
- Are there alternatives to AsyncEventDispatcher for Laravel?
- Yes, consider Laravel’s built-in queues (with `dispatch()`) or packages like `spatie/laravel-queueable-events` for event-to-job conversion. This package is niche—best for pub/sub patterns where queues aren’t ideal.