承接 pdffiller/laravel-queue-qless 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 pdffiller/laravel-queue-qless 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 8
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-29