Laravel 使用不同的队列连接来调度 Jobs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34675930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Use different queue connection to dispatch Jobs
提问by Sameer Sheikh
I am using laravel 5.1and i am using the dispatch method to push the job onto the queue. But there are two kind of jobs and i have created and two queues for that in sqs. How should i achieve this?
我正在使用laravel 5.1,我正在使用 dispatch 方法将作业推送到队列中。但是有两种作业,我在sqs 中创建了两个队列。我应该如何实现这一目标?
采纳答案by agent47
This worked for me.
这对我有用。
//code to be used in the controller (taken from @jedrzej.kurylo above)
$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);
I think this dispatches the job on to the queue named "emails". To execute the job dispatched on 'emails' queue:
我认为这会将作业分派到名为“电子邮件”的队列中。要执行在“电子邮件”队列上分派的作业:
//Run this command in a new terminal window
php artisan queue:listen --queue=emails
回答by jedrzej.kurylo
In order to specify the queue you need to call onQueue()method on your job object, e.g.:
为了指定队列,您需要在作业对象上调用onQueue()方法,例如:
$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);
If you want to send the job to a connection other than default, you need to do fetch connection manually and send the job there:
如果要将作业发送到默认连接以外的连接,则需要手动获取连接并将作业发送到那里:
$connection = Queue::connection('connection_name');
$connection->pushOn('queue_name', $job)
回答by markashworth
I'd suggest this:
我建议这样做:
app('queue')->connection('connection_name')->pushOn('queue_name', $job);
From here: In Laravel how to create a queue object and set their connection without Facade