elandlord/nats-php
Laravel-friendly PHP client for NATS messaging. Publish/subscribe, request/reply, and queue groups with a simple API. Suitable for event-driven apps, microservices, and background jobs needing fast, lightweight broker communication.
Illuminate\Queue adapter), but can be bolted onto Laravel’s queue system via custom drivers or as a complementary event bus.php-nats) must be installed separately. Version alignment with Laravel’s PHP version (e.g., 8.2+) is critical.NATSERR_* codes) must be translated to Laravel-friendly exceptions or logged centrally.event(new MyEvent) with nats->publish('events.my-event', $payload).Illuminate\Queue\Queue to delegate to NATS (e.g., NatsQueue driver).php-nats directly.rdkafka), or Pulsar.Connection class to publish/subscribe manually.NatsQueue driver extending Illuminate\Queue\Queue.push(), pop(), and delete() to interact with JetStream.// config/queue.php
'connections' => [
'nats' => [
'driver' => 'nats',
'url' => env('NATS_URL', 'nats://localhost:4222'),
'stream' => env('NATS_STREAM', 'laravel-jobs'),
],
];
Event::dispatch() with NATS publishes where cross-service communication is needed.ExplicitAck) for reliability.Event::dispatch() or Bus::dispatch() calls.nats->subscribe() or JetStream consumers.| Step | Dependency | Risk Mitigation |
|---|---|---|
| 1. Set up NATS | NATS server access | Use Docker for local testing. |
| 2. Install Package | elandlord/nats-php + php-nats |
Composer require-dev for CI testing. |
| 3. Pilot Events | Non-critical event flows | Rollback to Laravel Events if needed. |
| 4. Queue Driver | Custom NatsQueue implementation |
Start with a single queue worker. |
| 5. JetStream Streams | Stream configuration | Use NATS CLI to manage streams initially. |
| 6. Monitoring | Metrics integration | Start with basic logging. |
elandlord/nats-php for breaking changes (low stars = potential abandonment risk).| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| NATS Server Down | All NATS-dependent jobs fail | Circuit breakers; fallback to local DB queue. |
| JetStream Stream Corruption | Lost messages or duplicate procs | Enable JetStream mirroring or backups. |
| Consumer Lag | Slow processing | Scale consumers; adjust MaxDeliver policy. |
| Network Partition | Subscribers miss messages | Use JetStream ack wait and retries. |
| Laravel Worker Crash | Unacked messages pile up | Implement dead-letter streams in JetStream. |
How can I help you explore Laravel packages today?