Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Nats Laravel Package

basis-company/nats

PHP NATS client with support for TLS and JWT auth, pub/sub and request/reply patterns, plus JetStream APIs (microservices, key-value storage). Configurable reconnect and retry delays. Install via Composer and connect with simple configuration.

View on GitHub
Deep Wiki
Context7

nats jetstream client for php

Frequently asked questions about Nats
How do I integrate NATS JetStream with Laravel’s queue system for job processing?
Use the package’s JetStream API to create streams and consumers, then bind them to Laravel’s queue system. For example, fetch jobs from a NATS stream in a consumer and dispatch them via `dispatch(new ProcessJob($payload))`. You can also extend Laravel’s queue drivers to support NATS by creating a custom `NatsQueue` driver.
Does this package support Laravel’s event system for publishing/subcribing to NATS topics?
Yes, you can publish Laravel events to NATS subjects by hooking into the `Event::dispatch()` method and forwarding messages to NATS. Conversely, subscribe to NATS subjects and dispatch Laravel events (e.g., `Event::dispatch(new UserCreated(...))`) when messages arrive. This bridges NATS and Laravel’s event ecosystem seamlessly.
What Laravel versions and PHP requirements does `basis-company/nats` support?
The package supports Laravel 9 and 10 with PHP 8.1+. It requires no additional PHP extensions beyond `libsodium` (for NKey/JWT) or `sodium_compat` as a fallback. Ensure your Laravel app meets these requirements before installation.
How do I configure TLS and JWT authentication for secure NATS connections in Laravel?
Configure TLS by setting the `tls` option in the `Configuration` object (e.g., `new Configuration(['tls' => true])`). For JWT, use the `user` and `pass` fields with your credentials or configure NKey authentication via `Configuration::setUser()` and `Configuration::setPass()`. The package handles TLS handshakes and JWT validation automatically.
Can I use NATS JetStream as a drop-in replacement for Redis queues in Laravel?
While NATS JetStream offers higher throughput and advanced features like message retention, it isn’t a direct drop-in. You’ll need to migrate queue workers to consume from NATS streams instead of Redis. Benchmark performance (e.g., with `phpbench`) to compare latency and throughput before full migration.
How do I handle reconnection and retry delays when NATS is unstable in production?
The package supports configurable retry delays (constant, linear, or exponential backoff). Set delays via `setDelay()` (e.g., `$config->setDelay(0.01, Configuration::DELAY_EXPONENTIAL)`). For production, use exponential backoff to avoid overwhelming NATS during outages.
Is there a way to monitor NATS consumers and streams in Laravel using Horizon or Telescope?
Yes, extend Laravel Horizon to monitor NATS consumers by creating custom metrics for stream health, message counts, or consumer lag. For Telescope, log NATS events (e.g., publishes, acks) via middleware or service provider hooks to track activity in the Laravel debug panel.
How do I migrate from Redis queues to NATS JetStream without downtime?
Start by dual-writing to both Redis and NATS for non-critical queues (e.g., notifications). Gradually replace Redis consumers with NATS consumers, then decommission Redis queues. Use NATS’s key-value store for shared state (e.g., cache) to reduce Redis dependency.
What are the performance differences between NATS JetStream and Laravel’s default database queues?
NATS JetStream handles **360k+ messages per second** with low latency, while Laravel’s database queues are limited by SQL overhead. JetStream also supports batching, ephemeral consumers, and work queues—ideal for high-throughput workloads like IoT or real-time analytics.
Are there alternatives to this package for NATS in Laravel, and when should I choose them?
Alternatives include `php-nats` (low-level) or `reactphp/nats` (async). Use this package if you need **JetStream APIs, Laravel integration, or microservices routing**. Choose `php-nats` for raw NATS control or `reactphp/nats` for async event loops in non-Laravel apps.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php