- How do I replace Laravel’s Event::dispatch() with this service bus in my existing app?
- Replace `Event::dispatch($event)` with `$bus->publish($event)` or `$bus->dispatch($command)`. The package integrates with Laravel’s service container, so handlers are resolved automatically via type-hinted dependencies. Start with a single event type in a non-critical module to test the migration path.
- Which Laravel versions and PHP versions does this package support?
- The package requires **PHP 8.0+** and is optimized for **Laravel 9/10**. Check the `composer.json` for exact version constraints, but it aligns with Laravel’s latest LTS releases. If using Laravel 8, verify compatibility with the package’s `laravel/framework` requirement.
- Can I use Redis as a broker instead of RabbitMQ for simplicity?
- Yes, Redis is the most Laravel-native option and recommended for simplicity. Configure it in `.env` with `PSERVICE_BUS_CONNECTION=redis` and ensure your `QUEUE_CONNECTION` also uses Redis. RabbitMQ/AMQP are supported but require additional setup for routing and persistence.
- How do I add middleware (e.g., retries, logging) to messages in the pipeline?
- Use Laravel’s middleware stack by binding middleware classes to the bus in your `AppServiceProvider`. For example, register a retry middleware via `$bus->pipe(RetryMiddleware::class)`. The package supports middleware for cross-cutting concerns like validation, logging, or dead-letter queue handling.
- What’s the best way to handle failed messages or dead-letter queues?
- Failed messages can be routed to a dead-letter queue by configuring a `DeadLetterQueueMiddleware` in the pipeline. For Redis, use a separate queue (e.g., `failed-jobs`). For RabbitMQ, leverage its built-in dead-letter exchanges. Monitor failures via Laravel Horizon or a third-party APM tool.
- Does this package work with Laravel Horizon for monitoring?
- Yes, Horizon can monitor bus consumers alongside queues. Register the bus workers in `config/horizon.php` under `processes`, and Horizon will track job throughput, failures, and retries. Instrument custom metrics if needed for observability.
- How do I test message handlers in isolation?
- Mock the bus interface in your tests using Laravel’s `Mockery` or PHPUnit’s `createMock()`. Inject the mock bus into handlers to verify interactions without requiring a real broker. The package’s IoC integration makes it easy to swap dependencies for unit testing.
- What’s the performance impact of using this vs. Laravel Queues directly?
- Performance depends on your broker: Redis offers low-latency pub/sub (~10K msg/sec with tuning), while RabbitMQ scales higher but adds complexity. Benchmark with your workload—start with Redis for simplicity, then optimize based on throughput needs (e.g., connection pooling, batching).
- Can I use this package for synchronous command handling (RPC-style) or just async events?
- The package supports both async events and synchronous commands via the `dispatch()` method. For RPC, ensure handlers are idempotent or use request-response patterns with a reply queue. Async is recommended for decoupling, but sync is possible for tightly coupled workflows.
- Are there alternatives to this package for Laravel service buses?
- Alternatives include **Laravel’s built-in Queues** (for simple async), **Symfony Messenger** (via `php-messenger`), or **RabbitMQ PHP Client** for raw control. This package stands out by combining PServiceBus’s EDA patterns with Laravel’s conventions (IoC, middleware, queues), offering a balanced trade-off between flexibility and ease of use.