Comments (6)
是支持多个队列的。
如果是 相同地域 和 账号,可以直接指定队列名称;
如果是 不同地域 或 账号,需要在 config/queue.php
里新增连接:
'connections' => [
//...
'your-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-30seconds
],
'topic' => [
'enable' => false,
'filter' => 'routing', //routing or msgtag
'host' => 'https://cmq-topic-region.api.qcloud.com',
'name' => '',
],
],
];
//...
];
分派 Job
时指定连接和队列
Job::dispatch()->onConnection('your-connection-name')->onQueue('queue-name-1');
Job::dispatch()->onConnection('your-connection-name')->onQueue('queue-name-2');
dispatch((new Job)->onConnection('your-connection-name')->onQueue('queue-name-1'));
dispatch((new Job)->onConnection('your-connection-name')->onQueue('queue-name-2'));
在 Job
内指定连接和队列
<?php
namespace App\Jobs;
class ProcessPodcast implements ShouldQueue
{
/**
* The name of the connection the job belongs to.
*/
protected $connectionName = 'your-connection-name';
/**
* The name of the queue the job belongs to.
*
* @var string
*/
protected $queue = 'your-queue-name';
}
处理指定的连接和队列
php artisan queue:work {connection-name} --queue={queue-name}
from laravel-queue-cmq.
.env
中的 CMQ_QUEUE
配置项只是 默认 的 队列名称,实际使用中是可以通过 onQueue
方法或 $queue
属性动态指定的,默认 的 连接名 是 cmq
$payload
目前为 Laravel
默认的格式,按照此格式生成都是可以解析的,但跨语言可能比较麻烦
{
"displayName":"App\\Jobs\\TestJob",
"job":"Illuminate\\Queue\\CallQueuedHandler@call",
"maxTries":null,
"timeout":null,
"data":{
"commandName":"App\\Jobs\\TestJob",
"command":"O:16:\"App\\Jobs\\TestJob\":4:{s:6:\"*job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:5:\"delay\";N;}"
}
}
后续会支持自定义 payload
from laravel-queue-cmq.
感谢您的回复,几个队列都在一个账号、同一地域下,唯有 queue name 不同
你说:“如果是 相同地域 和 账号,可以直接指定队列名称;”
能否给个示例?是在 env 文件中指定多个CMQ_QUEUE吗?
from laravel-queue-cmq.
还是指:php artisan queue:work {connection-name} --queue={queue-name}
执行此命令时,指定不同 --queue 参数即可?
from laravel-queue-cmq.
上面的问题已经解决,感谢您。
有个新问题,向 CMQ 写入消息的生产者,并不使用 laravel 框架,甚至是别的语言,如果继续用laravel 作为消费者,那消息的 payload 是不是要按照特定的格式生成?
from laravel-queue-cmq.
感谢,后来琢磨出来了,laravel 会默认调用CallQueuedHandler 的 fire 函数,像上面如果指定了 call 函数,那CallQueuedHandler必须声明一个 call 函数
多谢指点,已经顺利运行
from laravel-queue-cmq.
Related Issues (13)
- 消费队列时异常 HOT 1
- 不能支持laravel 5.2的版本 HOT 2
- 能否麻烦写一下关于发布消息,消费消息的小demo,没有研究明白该如何使用 HOT 10
- 队列任务处理失败时无法记录到数据库 HOT 4
- Class 'Freyo\LaravelQueueCMQ\Queue\Driver\Message' not found HOT 1
- laravel 版本依赖说明 HOT 2
- Nonce 重复导致请求失败 HOT 4
- 是否支持最新版CMQ HOT 1
- 支持下laravel 5.6 HOT 1
- 需要允许通过配置设置poll的时长 HOT 1
- Pop the next job off of the queue. HOT 1
- logFailedJob HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-queue-cmq.