freyo/laravel-queue-cmq
Composer 安装命令:
composer require freyo/laravel-queue-cmq
包简介
Queue Adapter for Tencent Qcloud CMQ SDK
关键字:
README 文档
README
Tencent Cloud Message Queue Driver for Laravel Queue
Installation
composer require freyo/laravel-queue-cmq
Configure
Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
config/app.php:
'providers' => [ // ... Freyo\LaravelQueueCMQ\LaravelQueueCMQServiceProvider::class, ]
.env:
QUEUE_DRIVER=cmq
CMQ_SECRET_KEY=
CMQ_SECRET_ID=
CMQ_QUEUE_HOST=https://cmq-queue-{region}.api.qcloud.com
CMQ_QUEUE=queue_name #default queue name
CMQ_QUEUE_POLLING_WAIT_SECONDS=0
CMQ_TOPIC_ENABLE=false # set to true to use topic
CMQ_TOPIC_FILTER=routing # or msgtag
CMQ_TOPIC_HOST=https://cmq-topic-{region}.api.qcloud.com
CMQ_TOPIC=topic_name
Tips
-
Region should be replaced with a specific region: gz (Guangzhou), sh (Shanghai), or bj (Beijing).
-
Domain for public network API request: cmq-queue-region.api.qcloud.com / cmq-topic-region.api.qcloud.com
-
Domain for private network API request: cmq-queue-region.api.tencentyun.com / cmq-topic-region.api.tencentyun.com
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
Example
Dispatch Jobs
The default connection name is cmq
//use queue only Job::dispatch()->onConnection('connection-name')->onQueue('queue-name'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('queue-name')) //use topic and tag filter Job::dispatch()->onConnection('connection-name')->onQueue('tag1,tag2,tag3'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('tag1,tag2,tag3')) //use topic and routing filter Job::dispatch()->onConnection('connection-name')->onQueue('routing-key'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('routing-key'))
Multiple Queues
Configure config/queue.php
'connections' => [ //... 'new-connection-name' => [ 'driver' => 'cmq', 'secret_key' => 'your-secret-key', 'secret_id' => 'your-secret-id', 'queue' => 'your-queue-name', 'options' => [ 'queue' => [ 'host' => 'https://cmq-queue-region.api.qcloud.com', 'name' => 'your-queue-name', 'polling_wait_seconds' => 0, // 0-30 seconds 'retries' => 3, ], 'topic' => [ 'enable' => false, 'filter' => 'routing', // routing or msgtag 'host' => 'https://cmq-topic-region.api.qcloud.com', 'name' => 'your-topic-name', 'retries' => 3, ], ], 'plain' => [ 'enable' => false, 'job' => 'App\Jobs\CMQPlainJob@handle', ], ]; //... ];
Process Jobs
php artisan queue:work {connection-name} --queue={queue-name}
Plain Mode
Configure .env
CMQ_PLAIN_ENABLE=true
CMQ_PLAIN_JOB=App\Jobs\CMQPlainJobHandler@handle
Create a job implements PlainPayload interface. The method getPayload must return a sting value.
<?php namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Freyo\LaravelQueueCMQ\Queue\Contracts\PlainPayload; class CMQPlainJob implements ShouldQueue, PlainPayload { use Dispatchable, InteractsWithQueue, Queueable; protected $payload; /** * Create a new job instance. * * @return void */ public function __construct($payload) { $this->payload = $payload; } /** * Get the plain payload of the job. * * @return string */ public function getPayload() { return $this->payload; } }
Create a plain job handler
<?php namespace App\Jobs; use Illuminate\Queue\Jobs\Job; class CMQPlainJobHandler { /** * Execute the job. * * @param \Illuminate\Queue\Jobs\Job $job * @param string $payload * * @return void */ public function handle(Job $job, $payload) { // processing your payload... var_dump($payload); // release back to the queue manually when failed. // $job->release(); // delete message when processed. if (! $job->isDeletedOrReleased()) { $job->delete(); } } }
References
License
The MIT License (MIT). Please see License File for more information.
freyo/laravel-queue-cmq 适用场景与选型建议
freyo/laravel-queue-cmq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53.95k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2017 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「qcloud」 「laravel-queue」 「cmq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 freyo/laravel-queue-cmq 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freyo/laravel-queue-cmq 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 freyo/laravel-queue-cmq 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.
The package contains useful utilities and classes.
Native ext-amqp RabbitMQ queue driver for Laravel production workloads with connection pooling, publisher confirms, Horizon support, Octane support, quorum queues, and high-performance workers
Flysystem Adapter for Tencent Qcloud COS SDK V4
The qcloud extension for the yii framework
qclouds api
统计信息
- 总下载量: 53.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-15