Weave 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

A PHP client for NATS with publish/subscribe, request/response, JetStream, microservices, and key-value storage. Supports TLS and JWT authentication plus configurable retry delays.

View on GitHub
Deep Wiki
Context7

Basis Company NATS is a PHP client for NATS messaging, supporting core publish/subscribe, request/response, and JetStream workflows. It offers flexible connection configuration, including TLS, JWT authentication, and retry delay modes for resilient service connectivity.

  • Pub/Sub & Request/Response messaging for event-driven and RPC patterns.
  • JetStream API support for durable streams and message processing.
  • Key Value Storage and microservices utilities.
  • TLS/JWT auth plus configurable constant, linear, or exponential retries.
  • Composer installation; NKeys requires Ed25519 via libsodium or sodium_compat.
Frequently asked questions about Nats
What is basis-company/nats used for in Laravel applications?
It is a PHP client for NATS and JetStream that lets Laravel apps publish and subscribe to subjects, implement request/reply messaging, run microservice-style consumers, and use JetStream key-value storage. Teams typically reach for it when they need high-throughput event-driven workflows, async jobs, real-time notifications, or integration with existing NATS infrastructure. It is framework-agnostic, so Laravel integration is done through your own service provider and container bindings.
How do I install basis-company/nats in a Laravel project?
Install it with Composer using composer require basis-company/nats. If you use NKeys or JWT authentication, make sure the libsodium PHP extension is available or install the sodium_compat package as a fallback. Then create a Laravel service provider or config binding for the NATS client so it can be resolved from the container.
Does basis-company/nats provide a native Laravel queue driver or Horizon support?
No, the package is a PHP NATS client rather than a packaged Laravel queue driver. You can integrate it with Laravel by writing a custom queue driver, dispatching Laravel jobs from NATS consumers, or publishing Laravel events to NATS subjects. Horizon is built around Redis queues, so it does not monitor NATS consumers out of the box; you would need custom monitoring or Telescope instrumentation.
How do I connect to NATS with TLS or JWT authentication from Laravel?
Create a Basis\Nats\Configuration with your host and credentials, then pass it to Basis\Nats\Client; TLS connections typically use the same connection settings as non-TLS. For JWT or NKey auth, the client relies on Ed25519 support from libsodium or sodium_compat. Keep credentials in Laravel environment variables or a secrets manager and bind the configured client as a singleton.
Can I use NATS JetStream key-value storage instead of Redis in Laravel?
Yes, the package exposes JetStream key-value storage APIs, so you can use NATS as shared state for config, cache-like values, or coordination data. It is not a drop-in replacement for Laravel's Redis cache or session driver, so you would normally wrap the NATS KV client in your own repository or cache adapter. This approach works best when you already run NATS and want to reduce separate Redis dependencies.
How do I publish Laravel events to NATS subjects?
Register the NATS client in a Laravel service provider, then call the client's publish method from an event listener or a dedicated event subscriber. Use clear subject names such as user.created and validate the payload with a DTO or Form Request before publishing. For inbound messages, run NATS consumers as long-lived workers and dispatch Laravel events or jobs from the consumer callback.
What PHP and Laravel versions does basis-company/nats support?
The package is a framework-agnostic PHP client and is commonly used with Laravel 9 and 10 applications on PHP 8.1 or newer. Check the package's composer.json and release notes for the exact PHP constraint before upgrading. Laravel version support depends on your app's PHP version and how you wire the client into the container.
Is basis-company/nats a good replacement for Redis or RabbitMQ queues in Laravel?
It can be a good fit when you need NATS JetStream features such as persistent streams, work queues, retention policies, or high-throughput event messaging. Redis remains simpler for Laravel's built-in queue system, and RabbitMQ may be preferred if your team already has that operational expertise. A common approach is to pilot NATS on a non-critical queue before migrating core jobs.
How should I handle reconnects and retries with basis-company/nats in production?
Configure reconnect and retry delays through the Configuration object, using constant, linear, or exponential delay modes based on your failure profile. Add application-level retry and dead-letter handling around publishes and consumer acknowledgements, especially for JetStream work queues. Run consumers as supervised Laravel workers and log connection and consumer metrics so failures are visible.
Is basis-company/nats actively maintained and tested, and what are the alternatives?
The repository includes GitHub Actions testing and coverage badges, and it is distributed on Packagist as basis-company/nats. For Laravel teams, alternatives include Laravel's Redis or database queues, RabbitMQ packages, and other PHP NATS clients. Evaluate release activity, issue response, and your need for JetStream-specific features before adopting it for critical workloads.
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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels