https://github.com/jiyis/laravel-nsq
nsq client for laravel
https://github.com/jiyis/laravel-nsq
laravel nsq nsqlaravel nsqphp
Last synced: 3 months ago
JSON representation
nsq client for laravel
- Host: GitHub
- URL: https://github.com/jiyis/laravel-nsq
- Owner: jiyis
- Created: 2018-05-09T10:54:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-02T05:33:38.000Z (over 6 years ago)
- Last Synced: 2024-12-21T15:13:16.152Z (4 months ago)
- Topics: laravel, nsq, nsqlaravel, nsqphp
- Language: PHP
- Homepage:
- Size: 51.8 KB
- Stars: 9
- Watchers: 6
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Laravel Nsq Client
NSQ client for laravel## Requirements
| Dependency | Requirement |
| -------- | -------- |
| [PHP](https://secure.php.net/manual/en/install.php) | `>= 7.1.0` |
| [Swoole](https://www.swoole.co.uk/) | `The Newer The Better` `No longer support PHP5 since 2.0.12` |## Installation
```
pecl install swoole
```
```
composer require jiyis/laravel-nsq
```## Usage
#### Set env
```
NSQSD_URL=127.0.0.1:4150
NSQLOOKUP_URL=127.0.0.1:4161# If it is multiple, please separate them with ","
NSQSD_URL=127.0.0.1:4150,127.0.0.1:4250
```
#### Create Job
```
php artisan make:job NsqTestJob
```
you need set two property. `public $topic;` `public $channel;`
```php
class NsqTestJob implements ShouldQueue
{use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $topic = 'test';
public $channel = 'web';public function handle()
{
$client = $this->job->getCurrentClient();
$payload = json_decode($this->job->getMessage(), true);
...
}
}
```
#### Publish
```php
// the data you want to be publish
$str = [
'message' => 'this is a message',
'user_id' => 1
];
// not supported dispatch
Queue::connection('nsq')->push(new NsqTestJob, $str);
```
#### Subscribe
```
php artisan queue:work nsq --sleep=3 --tries=3 --timeout=500 --job=App\\Jobs\\NsqTestJob
```