PHPackages                             seddighi78/laravel-nats - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. seddighi78/laravel-nats

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

seddighi78/laravel-nats
=======================

Nats jetstream client for Laravel

v1.1.0(1y ago)63.5k↓27.8%1MITPHPPHP ^8.2

Since Oct 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/seddighi78/laravel-nats)[ Packagist](https://packagist.org/packages/seddighi78/laravel-nats)[ Docs](https://github.com/seddighi78/laravel-nats)[ RSS](/packages/seddighi78-laravel-nats/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Laravel-Nats
============

[](#laravel-nats)

This package provides an observer for the Laravel Nats push-based event system that uses Laravel events. it uses  for using Nats in php

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require seddighi78/laravel-nats
```

The package will automatically register itself.

You can optionally publish the config file with:

```
php artisan vendor:publish --provider="Seddighi78\LaravelNats\NatsServiceProvider"
```

Connection
----------

[](#connection)

You should set the config env parameters to connect to your NATS server. for example :

```
NATS_HOST=localhost
NATS_PORT=4222

```

other configuration parameters can be found in `config/nats.php`.

Usage
-----

[](#usage)

You need to run this command to subscribe to a subject and receive messages from the NATS server, it will dispatch a `MessageReceived.php` event when a new message is received and then you can listen to this event to do your job.

```
php artisan nats:subscriber:work {subject} {group?} {--connection=}
```

Arguments:

- `{subject}`: The name of your queue or stream (example: `main`)
- `{group?}`: (Optional) The consumer group name for the subscription. When specified, it enables NATS Queue Groups functionality.
- `{--connection}`: (Optional) The connection name to use.

### About NATS Queue Groups

[](#about-nats-queue-groups)

When you specify a group name, the subscriber becomes part of a queue group in NATS. Queue groups allow you to distribute messages across multiple subscribers for load balancing. Here's how it works:

- Without a group: Each subscriber receives a copy of every message (pub/sub pattern)
- With a group: Messages are distributed across subscribers in the same group (queue pattern)

Example usage:

```
# Start subscriber in a queue group named 'workers'
php artisan nats:subscriber:work orders workers

# Start multiple instances to distribute the load
php artisan nats:subscriber:work orders workers # Instance 1
php artisan nats:subscriber:work orders workers # Instance 2
```

In the example above, if you have multiple subscribers with the same group name, only one subscriber in the group will receive each message, enabling load balancing across your subscribers.

Example
-------

[](#example)

These files are examples of using the package:

### Subscribe

[](#subscribe)

Create a listener and listen to the `MessageReceived` event:

```
namespace App\Listeners;

use Seddighi78\LaravelNats\Events\MessageReceived;

class PrintOnNatsMessageReceivedListener
{
    public function handle(MessageReceived $event): void
    {
        echo $event->message; // you can process the message here
    }
}
```

add the listener to `EventServiceProvider`

```
use Seddighi78\LaravelNats\Events\MessageReceived;
use App\Listeners\PrintOnNatsMessageReceivedListener;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        MessageReceived::class => [
            PrintOnNatsMessageReceivedListener::class,
        ]
    ];
}
```

### Publish

[](#publish)

You can use this code to publish a message on a specific subject:

```
$client = app(\Seddighi78\LaravelNats\Factories\NatsClientFactoryInterface::class)->getClient();
$client->publish('main', 'test');
```

When a message is published and the command `nats:subscriber:work` is running, the `MessageReceived` event will be dispatched, and you can listen to this event to do your job.

Also you can use the facade for calling these methods:

```
use Seddighi78\LaravelNats\Facades\Nats;

// calling publish method
Nats::getClient()->publish('main', 'test');
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance45

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~43 days

Total

4

Last Release

428d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e9927d777a2f4eda2e5ad7e16fbc081d1702cd63434a962b51a63d878c2c390?d=identicon)[seddighi78](/maintainers/seddighi78)

---

Top Contributors

[![seddighi78](https://avatars.githubusercontent.com/u/29895767?v=4)](https://github.com/seddighi78 "seddighi78 (15 commits)")[![aroundajay](https://avatars.githubusercontent.com/u/10551117?v=4)](https://github.com/aroundajay "aroundajay (3 commits)")

---

Tags

laravelpub-subnats

### Embed Badge

![Health badge](/badges/seddighi78-laravel-nats/health.svg)

```
[![Health](https://phpackages.com/badges/seddighi78-laravel-nats/health.svg)](https://phpackages.com/packages/seddighi78-laravel-nats)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[anahkiasen/former

A powerful form builder

1.4k1.4M14](/packages/anahkiasen-former)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
