我想将消息并行或一个接一个地推送到多个SQS队列,但它应该是动态的,当我启动worker时,它应该从两个队列中获取消息并进行区分。 我怎样才能在Lumen实现这一目标? UPDATE 如何使用多个worker来处理具有不同amazon SQS实例的不同队列?
据我所知,Lumen和Laravel使用完全相同的代码来处理队列,所以这里可能有用,但我还没有测试过。
运行队列工作器:
php artisan queue:work --queue=queue1,queue2
这意味着queue1中的作业在queue2中的作业之前被处理(不幸的是,这是侦听多个队列的唯一方法)
然后在你的工作:
class MyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
if ($this->job->getQueue() === 'queue1') {
//Things
} else {
// different things
}
}
如果您需要使用多个连接,则无法使用单个工作程序执行此操作,但是您可以一次使用多个工作程序。首先配置连接,例如在你的config/queue.php
'connections' => [
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'sqs2' => [
'driver' => 'sqs',
'key' => 'your-other-public-key',
'secret' => 'your-other-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-other-account-id',
'queue' => 'your-other-queue-name',
'region' => 'us-east-1',
],
]
如果您正在使用主管,那么请设置您的主管配置,否则您必须手动启动两个工作人员。这是您可以使用的主管配置:
[program:laravel-sqs-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs --queue=queue1
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
[program:laravel-sqs2-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs2 --queue=queue2
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
根据您的应用更改路径和用户设置。