Download the PHP package airygen/laravel-amqp-producer without Composer
On this page you can find all versions of the php package airygen/laravel-amqp-producer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download airygen/laravel-amqp-producer
More information about airygen/laravel-amqp-producer
Files in airygen/laravel-amqp-producer
Package laravel-amqp-producer
Short Description RabbitMQ publisher for Laravel with confirms, retries, DLX strategy.
License MIT
Informations about the package laravel-amqp-producer
Laravel AMQP Producer
Laravel-oriented RabbitMQ publisher with:
- Publisher confirms
- Mandatory publish (detect unroutable messages)
- Exponential retry for transient AMQP errors
- Structured automatic headers:
request_id,source,env, ISO8601datetime - Multi-connection support (choose connection per payload)
This library focuses on publishing only. For queue workers / consumers you can use: vyuldashev/laravel-queue-rabbitmq.
Installation
Publish Configuration
Generated file: config/amqp.php
Defining a Payload
Extend ProducerPayload and (optionally) override connection / exchange / routing key.
Basic Publish
Custom Headers
Batch Publish
Retry Strategy
The publisher retries transient AMQP IO / protocol errors (IO / protocol channel exceptions) with exponential backoff:
- Initial delay
base_delay(~200ms), doubled each attempt, capped atmax_delay(~1500ms) - Default attempts: 3
Custom rule:
Disable retry: Enable jitter:
Jitter multiplies each delay by a random factor ~0.85 - 1.15.
Multi-Connection Example
Automatic Headers Added
MessageFactory injects:
request_id(existingX-Request-Idheader or a new UUID)source(Laravel app name)env(current environment)datetime(ISO8601)
You can still provide additional custom headers; your keys override defaults if duplicated.
Header precedence: custom headers provided in publish() / batchPublish() override automatically injected keys when the same key exists.
Metrics & Stats
The package ships with an in-memory static counter registry Stats intended for lightweight instrumentation or exporting into your own monitoring system.
Global counters:
publish_attemptspublish_retriespublish_failuresconnection_resets
Per‑connection counters (nested under per_connection[connection_name]):
publish_attemptspublish_retriespublish_failuresconnection_resets
Example snapshot:
You can reset counters (e.g. at the start of a test or scheduled export) with:
For production telemetry, consider periodically reading the snapshot and pushing to Prometheus / OpenTelemetry.*
Note: These counters are process‑local (not shared across workers). If you run Octane/Swoole multi-worker, aggregate externally.
Behavior: Always Open/Close
For operational safety across PHP-FPM/CLI and worker runtimes (Octane/Swoole/RoadRunner), this package always opens a fresh channel for each publish and closes both channel and connection afterwards.
Octane / Swoole / RoadRunner
Health Check Command
Run a simple connectivity probe:
Exit code is non‑zero on failure (suitable for container readiness / liveness probes). Long-lived worker environments reuse PHP processes, so you must ensure stale connections/channels don't leak across deploys or forks.
Built-in safeguards:
- On worker start/stop (Octane events) the connection manager
reset()is invoked (if Octane is installed). - Connections are opened and closed per publish; you can call
ConnectionManager::reset()manually if desired.
Recommended practices:
- Avoid holding a
Publisherinstance in static singletons you construct before workers fork. - Call
app(ProducerInterface::class)per request/job (container will reuse safe singleton manager underneath). - If you rotate workers periodically, no extra action is needed—the hook already clears state.
- For Swoole without Octane events, you can manually schedule:
ConnectionManager::reset()during your custom lifecycle hooks.
Optional manual reset example:
TLS / SSL (Optional)
If you need TLS encryption, enable and configure the SSL related options inside config/amqp.php:
The factory will build a stream context when ssl is truthy and any of the certificate fields are present. If verify_peer is enabled, ensure cafile is supplied.
Roadmap
- Pluggable metrics exporter interface
- Circuit breaker / total backoff budget
- Async publisher confirm pipeline
- Mandatory publish return callbacks (unroutable detection)
- Dead letter / delayed publish helpers
Development
Dockerized Workflow
All commands are wrapped to run inside the php service defined in docker-compose.yml.
Startup & install:
Using Makefile targets:
Manual (host) without Docker wrapper:
Management UI: http://localhost:15672 (guest / guest)
If you prefer to run host-native (without docker) use the host:* scripts or call PHPUnit directly.
Prometheus Metrics (Skeleton)
The package keeps lightweight in-memory counters (not persisted). A minimal Prometheus text exporter is provided.
Artisan command:
Example output:
Per-connection metrics are emitted with a connection label, e.g.:
You can bind your own implementation of Airygen\\RabbitMQ\\Contracts\\MetricsExporterInterface if you need richer aggregation or to integrate with an existing metrics system.
License
MIT
All versions of laravel-amqp-producer with dependencies
illuminate/support Version ^10.0 || ^11.0 || ^12.0
php-amqplib/php-amqplib Version ^3.5