pdffiller/laravel-queue-qless
Composer 安装命令:
composer require pdffiller/laravel-queue-qless
包简介
README 文档
README
Installation
You can install this package via composer using this command:
composer require pdffiller/laravel-queue-qless
The package will automatically register itself using Laravel auto-discovery.
Setup connection in config/queue.php
'connections' => [ // ... 'qless' => [ 'driver' => 'qless', 'redis_connection' => 'qless', 'queue' => 'default', ], // ... ],
Also you can set Qless queue as default in config/queue.php
'default' => env('QUEUE_DRIVER', 'qless'),
Redis connection in config/database.php
'redis' => [ 'client' => 'predis', // ... 'qless' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], // ... ],
And add Laravel Qless service provider to app.php
<?php return [ //... 'providers' => [ //... /** * Qless */ LaravelQless\LaravelQlessServiceProvider::class, ] ];
Usage
Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues
Also you can use additional features.
Topics
Topic help you to put a job to different queues.
First, you must to create a subscription. You can use pattern for name of topics.
Symbol * - one word, # - few words divided by point ..
Examples: first.second.*, *.second.*, #.third.
/** * Subscribe */ \Queue::subscribe('*.*.test', 'queue1'); \Queue::subscribe('this.*.test', 'queue2'); \Queue::subscribe('this.*.orange', 'queue3');
Than you can put job to all subscribers.
/** * Put job to few queues */ \Queue::pushToTopic('this.is.test', TestQless::class, ['test' => 'test']); // Push job to queue1 and queue2, but not to queue3
Custom Handler
Job Handler helps you to create a custom route for jobs.
Custom Handler example:
class CustomHandler implements JobHandler { public function perform(BaseJob $job): void { if ($job->getQueue() === 'queue_name') { // by queue (new QueueNameJob)->perform($job); return; } if ($job->getData()['option_name'] === 'value') { // by payload (new OptionNameJob)->perform($job); return; } if (in_array('tag_name', $job->getTags())) { // by tag (new TagNameJob)->perform($job); return; } // other $job->perform(); // Default } }
You must add to a service provider.
public function boot() { // other code $this->app->bind(JobHandler::class, CustomHandler::class); // other code }
Recurring Jobs
Sometimes it's not enough simply to schedule one job, but you want to run jobs regularly. In particular, maybe you have some batch operation that needs to get run once an hour and you don't care what worker runs it. Recurring jobs are specified much like other jobs:
/** * Recurring Job */ \Queue::recur($intervalInSeconds, $jobClass, $data, $queueName);
Sharding
If you compare Qless sharding with the DB sharding, then they have little in common. Qless gets random write-connection for all jobs. Data reading occurs in a circle from all connections.
Setup redis connections for sharding in config/database.php:
return [ 'redis' => [ // ... 'qless' => [ /* ... */ ], 'connection2' => [ /* ... */ ], 'connection3' => [ /* ... */ ], // ... ], ];
Then set the shards via redis_connection key in config/queue.php file:
return [ 'connections' => [ // ... 'qless' => [ // ... 'redis_connection' => [ 'connection2', 'connection3', ], // ... ], // ... ], ];
Testing
You can run the tests with:
vendor/bin/phpunit
Contribution
You can contribute to this package by discovering bugs and opening issues. Please, add to which version of package you create pull request or issue. (e.g. [1.2] Fatal error on push job)
License
Laravel Qless Queue driver is open-sourced software licensed under the MIT License.
See the LICENSE.txt file for more.
© 2018-2019 PDFfiller
All rights reserved.
pdffiller/laravel-queue-qless 适用场景与选型建议
pdffiller/laravel-queue-qless 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.61k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2018 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「laravel」 「jobs」 「qless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pdffiller/laravel-queue-qless 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pdffiller/laravel-queue-qless 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pdffiller/laravel-queue-qless 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
This module enables subscription to latest jobs by email
Super-simple, minimum abstraction Lever DATA API v1 wrapper in PHP with support for Laravel.
Message queue statistics for OroPlatform
Redis backed library for creating background jobs and processing them later.
统计信息
- 总下载量: 21.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-29