jiyis / laravel-nsq
Laravel 队列的 NSQ 驱动器
1.0.2
2018-08-01 07:51 UTC
Requires
- php: >=7.0
- illuminate/database: ^5.1
- illuminate/queue: ^5.1
- illuminate/support: ^5.1
Requires (Dev)
- illuminate/events: ^5.1
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
Suggests
- ext-swoole: Event-driven asynchronous & concurrent & coroutine networking engine with high performance for PHP.
This package is not auto-updated.
Last update: 2024-09-15 07:30:46 UTC
README
laravel 的 NSQ 客户端
要求
安装
pecl install swoole
composer require jiyis/laravel-nsq
使用方法
设置环境变量
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
创建工作
php artisan make:job NsqTestJob
你需要设置两个属性。 public $topic;
public $channel;
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); ... } }
发布
// 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);
订阅
php artisan queue:work nsq --sleep=3 --tries=3 --timeout=500 --job=App\\Jobs\\NsqTestJob