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

v2.0.0(1mo ago)64.2k—3.8%1MITPHPPHP ^8.2

Since Oct 30Pushed 1mo 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 3d ago

READMEChangelog (5)Dependencies (6)Versions (7)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

49

—

FairBetter than 94% of packages

Maintenance89

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~111 days

Recently: every ~138 days

Total

6

Last Release

56d ago

Major Versions

v1.2.0 → v2.0.02026-05-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29895767?v=4)[Alireza Seddighi](/maintainers/seddighi78)[@seddighi78](https://github.com/seddighi78)

---

Top Contributors

[![seddighi78](https://avatars.githubusercontent.com/u/29895767?v=4)](https://github.com/seddighi78 "seddighi78 (18 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

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k12.5k1](/packages/vinkius-labs-laravel-page-speed)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)

PHPackages © 2026

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