- How do I replace Laravel’s default queue driver with enqueue/amqp-ext for RabbitMQ?
- Install the enqueue/laravel package and configure your `config/queue.php` to use the AMQP transport. Set the `driver` to `enqueue` and provide a DSN like `amqp://user:pass@rabbitmq:5672/%2f`. Ensure the `ext-amqp` PHP extension is installed via PECL. No additional code changes are needed for basic usage.
- What Laravel versions and PHP requirements does enqueue/amqp-ext support?
- This package supports Laravel 10+ and requires PHP 8.1+. The underlying `ext-amqp` extension must be installed (v1.9.3 or v2.0.0). Check compatibility with your Laravel runtime by verifying the extension is loaded via `php -m | grep amqp`.
- Can I use enqueue/amqp-ext for standalone AMQP tasks without Laravel’s queue system?
- Yes. Use the `AmqpConnectionFactory` class to create direct AMQP connections. This is ideal for cross-service communication or event-driven workflows outside Laravel’s queue system. Example: Inject the factory into a service and publish messages to RabbitMQ without queue workers.
- How does enqueue/amqp-ext handle message persistence and reliability compared to Laravel’s database queue?
- AMQP brokers like RabbitMQ persist messages to disk by default, offering better reliability than Laravel’s database queue for high-throughput workloads. However, you must configure acknowledgments (`ack`) and prefetch counts to manage consumer reliability. Use `enqueue/amqp-tools` for retry logic and dead-letter queues.
- What are the performance benefits of using the PHP amqp extension over other Enqueue transports?
- The native `ext-amqp` extension provides lower-latency communication with RabbitMQ compared to HTTP-based transports (e.g., enqueue/amqp-lib). It’s optimized for high-throughput scenarios like video processing or real-time event sourcing, but requires the extension to be installed system-wide.
- How do I configure custom AMQP exchanges, bindings, or QoS settings with enqueue/amqp-ext?
- Use the `AmqpContext` class to define custom configurations, such as exchange types (direct, topic), bindings, or QoS settings like prefetch counts. Example: `$context = new AmqpContext(['exchange' => ['name' => 'my_exchange', 'type' => 'topic']]);`. Pass this to your connection factory for advanced routing.
- Are there alternatives to enqueue/amqp-ext for Laravel AMQP integration?
- Yes. Alternatives include `php-amqplib` (pure PHP, no extension) or `vladimir-yuldashev/laravel-queue-rabbitmq` (Laravel-specific). However, `enqueue/amqp-ext` offers better performance via the native extension and full `amqp-interop` compliance, making it ideal for production-grade async workflows.
- How do I monitor message latency or consumer lag when using enqueue/amqp-ext?
- Use RabbitMQ’s management plugin for metrics like message rates, consumer lag, and broker health. For Laravel, integrate tools like `enqueue/amqp-tools` for inspection or add custom health checks via Laravel’s `Artisan` commands. Monitor prefetch counts and QoS settings to avoid bottlenecks.
- What’s the best way to handle AMQP broker downtime or connection failures?
- Implement circuit breakers or local retries using `enqueue/amqp-tools`. Configure dead-letter exchanges to route failed messages for later reprocessing. For Laravel, use the `failed` queue table or custom logic to handle transient failures gracefully.
- Does enqueue/amqp-ext support delayed messages or message TTL (time-to-live)?
- Yes. Configure delayed messages via RabbitMQ’s `x-dead-letter-exchange` or use the `AmqpContext` to set TTL headers. Example: `$message->setDelay(60000)` for a 1-minute delay. Ensure your broker supports these features (RabbitMQ does by default).