{"id":44871418,"url":"https://github.com/goodway/laravel-nats","last_synced_at":"2026-02-17T13:05:39.509Z","repository":{"id":230786652,"uuid":"780176324","full_name":"goodway/laravel-nats","owner":"goodway","description":"Nats jetstream queue adapter with client for Laravel framework","archived":false,"fork":false,"pushed_at":"2025-10-27T10:24:53.000Z","size":229,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-27T14:59:22.641Z","etag":null,"topics":["jetstream","laravel","nats","php","queue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goodway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-31T22:47:10.000Z","updated_at":"2025-11-19T14:47:11.000Z","dependencies_parsed_at":"2024-04-12T02:38:49.226Z","dependency_job_id":"3237da21-1a58-4efa-8271-3c59c88979cb","html_url":"https://github.com/goodway/laravel-nats","commit_stats":null,"previous_names":["goodway/laravel-nats"],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/goodway/laravel-nats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodway%2Flaravel-nats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodway%2Flaravel-nats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodway%2Flaravel-nats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodway%2Flaravel-nats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goodway","download_url":"https://codeload.github.com/goodway/laravel-nats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodway%2Flaravel-nats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29545295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T13:00:00.370Z","status":"ssl_error","status_checked_at":"2026-02-17T12:57:14.072Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jetstream","laravel","nats","php","queue"],"created_at":"2026-02-17T13:05:37.248Z","updated_at":"2026-02-17T13:05:39.495Z","avatar_url":"https://github.com/goodway.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nats JetStream queue driver for Laravel\n\nWith multiple flexible client and queue configurations,\nwith events and customizable handlers\n\n\n[![PHP Version Requirement](https://img.shields.io/packagist/dependency-v/goodway/laravel-nats/php)](https://packagist.org/packages/goodway/laravel-nats)\n[![Latest Version](https://img.shields.io/github/release/goodway/laravel-nats.svg)](https://github.com/goodway/laravel-nats/releases)\n[![License](https://poser.pugx.org/goodway/laravel-nats/license.png)](https://packagist.org/packages/goodway/laravel-nats)\n[![Total Downloads](https://img.shields.io/packagist/dt/goodway/laravel-nats.svg)](https://packagist.org/packages/goodway/laravel-nats)\n\n---\n![Scheme](assets/img/base_showcase.png)\n\n\nFeel free to contribute or give any feedback.\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Publishing](#publishing-to-queue)\n- [Listening](#listening-from-queuejetstream-subject)\n- [Message](#message-object-structure)\n- [Events](#events)\n\n## Prerequisites\n\n#### Laravel Version\nThis package can be used in Laravel 8 or higher. The minimum PHP version required is 8.1\n\n#### Config file\nThis package publishes a config/nats.php file. \nIf you already have a file by that name, you must rename or remove it,\nas it will conflict with this package.\nYou could optionally merge your own values with those required by this package,\nas long as the keys that this package expects are present.\nSee the source file for more details.\n\n#### Nats Client\nAs a Nats client \nwe use an external [basis-company/nats.php](https://github.com/basis-company/nats.php) package - \nthe most popular, well-written and functional Nats client for PHP.\nGreatest thanks to Dmitry Krokhin ([nekufa](https://github.com/nekufa))!\n\n\n## Installation\nThe recommended way to install the library is through [Composer](http://getcomposer.org):\n```bash\n$ composer require goodway/laravel-nats\n```\n\nYou should publish \nthe [config/nats.php](https://github.com/goodway/laravel-nats/blob/main/config/nats.php) \nconfig file with:\n```bash\n$ php artisan vendor:publish --provider=\"Goodway\\LaravelNats\\LaravelNatsProvider\"\n```\n\n## Configuration\n\n### Client connection\n\nThe client connection configuration is specified in the config/nats.php file.\nMultiple configuration supported\n```\n    'client' =\u003e [\n        'configurations' =\u003e [\n            'default' =\u003e [\n                'host' =\u003e env('NATS_HOST', 'localhost'),\n                'port' =\u003e intval(env('NATS_PORT', 4222)),\n                'user' =\u003e env('NATS_USER'),\n                'password' =\u003e env('NATS_PASSWORD'),\n                'token' =\u003e env('NATS_TOKEN'), // Sets an authorization token for a connection\n                'nkey' =\u003e env('NATS_NKEY'), // new, highly secure public-key signature system based on Ed25519\n                'jwt' =\u003e env('NATS_JWT'), // Token for JWT Authentication\n                'reconnect' =\u003e env('NATS_RECONNECT', true),\n                'connection_timeout' =\u003e floatval(env('NATS_CONNECTION_TIMEOUT', 1)), // Number of seconds the client will wait for a connection to be established\n                'verbose_mode' =\u003e env('NATS_VERBOSE_MODE', false), // Turns on +OK protocol acknowledgements\n                'inbox_prefix' =\u003e env('NATS_INBOX_PREFIX', '_INBOX'), // Sets default prefix for automatically created inboxes\n                'ping_interval' =\u003e intval(env('NATS_PING_INTERVAL', 2)), // Number of seconds between client-sent pings\n                'ssl_key' =\u003e env('NATS_SSL_KEY_FILE'),\n                'ssl_cert' =\u003e env('NATS_SSL_CERT_FILE'),\n                'ssl_ca' =\u003e env('NATS_SSL_CA_FILE'),\n            ],\n            ...\n        ]\n    ]\n```\n\n\n### Queue connection\n\nDescribe the queue connection configuration in your 'config/queue.php' file.\nIt supports multiple client configurations.\n\nExample:\n```\n    'nats' =\u003e [\n        'driver' =\u003e 'nats',\n        'consumer_client' =\u003e 'default', // client configuration name from nats.php config file to listen queue\n        'publisher_client' =\u003e 'default', // client configuration name from nats.php config file to publish queue\n        'jetstream' =\u003e env('NATS_JETSTREAM', 'jetstream'),\n        'jetstream_retention_policy' =\u003e env('NATS_JETSTREAM_RETENTION_POLICY', 'workqueue'),\n        'consumer' =\u003e env('NATS_CONSUMER_GROUP', 'consumer'),\n        'consumer_iterations' =\u003e intval(env('NATS_CONSUMER_ITERATIONS', 3)),\n        'queue_consumer_create' =\u003e (bool)env('NATS_QUEUE_CONSUMER_CREATE', false),\n        'queue_consumer_prefix' =\u003e env('NATS_QUEUE_CONSUMER_PREFIX', 'con'),\n        'queue_separated_clients' =\u003e env('NATS_QUEUE_SEPARATE_IDENTICAL_CLIENTS', true), // separate Nats clients with the identical configuration\n        //            'queue_handler' =\u003e 'someClass',\n        'fire_events' =\u003e (bool)env('NATS_QUEUE_MESSAGE_EVENTS', true),\n        'default_batch_size' =\u003e intval(env('NATS_DEFAULT_BATCH_SIZE', 10)),\n        'verbose_mode' =\u003e (bool)env('NATS_QUEUE_VERBOSE_MODE', true),\n        'check_jetstream_publish' =\u003e (bool)env('NATS_QUEUE_CHECK_JETSTREAM_PUBLISH', false)\n    ],\n```\n\n\nFields description:\n\n- **driver** - [string] queue driver name. Use 'nats'\n- **consumer_client** - [string] client configuration name used to listen queue\n- **publisher_client** - [string] client configuration name used to publish messages\n- **jetstream** - [string] nats jetstream name\n- **jetstream_retention_policy** - [string] jetstream retention policy. Used on queue listening to generate the correct consumer name\n- **consumer** - [string] consumer group. Used for the final name of the consumer\n- **consumer_iterations** - [int, optional, 2] how many times message request should be sent\n- **consumer_delay** - [float, optional, 1] how long to wait (in sec.) before sending the next request if an empty response was received\n- **queue_consumer_create** - [bool] if true, Queue will try to automatically create a new consumer if one is not found.\nThis functionality only works if the current connection client has the necessary permissions to create a consumer\n- **queue_consumer_prefix** - [string] consumer prefix. Used for the final name of the consumer\n- **queue_separated_clients** - [bool] see description below\n- **fire_events** - [bool] if true then events will be fired during the publishing and handling received messages processes\n- **default_batch_size** - [int, optional, 10] batch size. How many messages would be requested from nats stream\n- **queue_handler** - [string, optional] classname of your custom queue handler. If not defined, then the standard handler will be used\n- **verbose_mode** - [bool, optional, false] var_dump some additional info. For example on publishing\n- **check_jetstream_publish** [bool, optional, false] - additionally check for the existence of a jetstream with each PUB.\nWhen enabled, it can significantly slow down performance because in this case an additional request-response to the Jetstream API is required\n\nYou can specify one connection for publisher and another one for consumer,\nor use one connection for both roles.\n\nYou can also use one or separate connections\nif the publisher client configuration name matches the consumer client configuration.\nUse this feature through the **\"queue_separated_clients\"** bool attribute.\n\n## Publishing to queue\n\nThe easiest way to send a message to queue is to call a dispatch() method on a simple class\nthat extends NatsMessageJob. The class must contain a body() method\nthat will return the contents of the message.\nReturn type for body() is string.\n\nExample:\n```\nuse Goodway\\LaravelNats\\NatsMessageJob;\n\nclass TestNatsJob extends NatsMessageJob\n{\n    public function body(): string\n    {\n        return json_encode([\n            'msd_id' =\u003e $this-\u003emsgId,\n            'push_data' =\u003e ['some_field' =\u003e md5($this-\u003emsgId)]\n        ]);\n    }\n}\n```\n\nYou can also use a dynamic body by passing content through the constructor.\n\nNatsMessageJob class uses Dispatchable and Queueable concerns and implements classic ShouldQueue interface.\nExamples:\n\n```\ndispatch((new TestNatsJob())\n    -\u003eonConnection('nats')\n    -\u003eonQueue('jetstream_subject');\n```\n```\nTestNatsJob::dispatch()\n    -\u003eonConnection('nats')\n    -\u003eonQueue('jetstream_subject');\n```\n\nYou can also specify the subject and jetstream for message using the \\$subject\nand \\$jetstream variables\n```\nclass\n    protected string $subject = 'mySubject';\n```\nor\n```\ndispatch((new TestNatsJob())\n    -\u003esetSubject('mySubject'))\n    -\u003eonConnection('nats')-\u003eonQueue('queue-name');\n```\n\n### DispatchNats\n\nThis package provides an additional dispatch mechanism\nand a corresponding helper with the **dispatchNats()** function.\nIt supports additional functions designed to make it easier\nto understand and interact with publishing.\n\nWith **dispatchNats** You can set a specific jetstream or subject\nwhen dispatching a job. And also specify whether to call events.\n\n**Examples:**\n\nWith helper function\n```\ndispatchNats((new TestNatsJob())\n    -\u003eonConnection('nats')\n    -\u003eonJetstream('jetstream_name')\n    -\u003eonSubject('jetstream_subject')\n    -\u003ewithEvents();\n```\nWith class static function\n```\nTestNatsJob::dispatchNats()\n    -\u003eonConnection('nats')\n    -\u003eonJetstream('jetstream_name')\n    -\u003eonSubject('jetstream_subject')\n    -\u003ewithoutEvents();\n```\n\n\n### Headers\n\nYou can set a message headers using the headers() method of your class. Example:\n\n```\nclass TestNatsJob extends NatsMessageJob\n{\n    public function headers(): array\n    {\n        return [\n            'header1_key' =\u003e 'header1_value',\n            'header2_key' =\u003e 'header2_value',\n        ];\n    }\n    ...\n}\n```\n\n\n## Listening from queue/jetstream subject\n\nYou can connect and listen to messages from the queue using standard **queue:work** mechanism.\nExample:\n\n```\nphp artisan queue:work nats --queue=queue-name\n```\n\n### queue:work command options (Recommended)\n\nThis package also extends the **queue:work** command and provides\nadditional options that allow you to specify a jetstream and consumer you want to connect to,\nas well as to set the batch size for reading messages.\n\n```\nphp artisan queue:work nats --jetstream=jetstream --consumer=durable_consumer --batch=50 --queue=any-name\n```\n**--consumer** option ignores the **--queue** option.\nIn this case, the **--queue** option will not be used in the connection logic,\nit is only needed for visual recognition of the queue for the developer.\n\n## Message object structure\n\n```\n{\n    \"body\": [string] any string: plain text, json-string or serialized data of your message\n    \"headers\": [array] headers array\n    \"subject\": [string] subject value\n    \"timestamp\": [int] timestamp in ms\n}\n```\n\n## Events\n\nThese events are fired during the publishing and listening processes.\n\n### NatsQueueMessageSent\n\nThis event is fired after a message is sent to the queue\n```\nclass NatsQueueMessageSent\n    ...\n    public function __construct(\n        public readonly string $jetstream,\n        public readonly string $subject,\n        public readonly NatsMessage $message\n    ) {}\n```\n\n### NatsQueueMessageReceived\n\nThis event is fired when a message is received from the queue\n```\nclass NatsQueueMessageReceived\n    ...\n    public function __construct(\n        public readonly string $jetstream,\n        public readonly string $subject,\n        public readonly NatsMessage $message\n    ) {}\n```\n\n\n---\n#### More documentation will be added soon...\n\n...\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodway%2Flaravel-nats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodway%2Flaravel-nats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodway%2Flaravel-nats/lists"}