Laravel 使用不同的队列连接来调度作业

Laravel Use different queue connection to dispatch Jobs

我正在使用 laravel 5.1 并且我正在使用调度方法将作业推送到队列中。 但是我在 sqs 中创建了两种工作和两个队列。 我该如何实现?

为了指定队列,您需要在作业对象上调用 onQueue() 方法,例如:

$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);

如果您想将作业发送到非默认连接,您需要手动获取连接并将作业发送到那里:

$connection = Queue::connection('connection_name');
$connection->pushOn('queue_name', $job)

这对我有用。

//code to be used in the controller (taken from @jedrzej.kurylo above)
$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);

我认为这会将作业分派到名为 "emails" 的队列中。 要执行在 'emails' 队列上分派的作业:

//Run this command in a new terminal window
php artisan queue:listen --queue=emails

我建议这样做:

app('queue')->connection('connection_name')->pushOn('queue_name', $job);

从这里开始: