gpt4 book ai didi

laravel - 如何使用队列设置高,低和中优先级的电子邮件?

转载 作者:行者123 更新时间:2023-12-03 14:46:21 25 4
gpt4 key购买 nike

我正在学习 Job dispatching from here

问题

我读到每个连接都有告诉队列名称的queue参数。问题是:如何设置发送低,中或高优先级电子邮件的优先级?

Cmd提示

我正在使用命令: php artisan queue:听来处理作业。

我尝试了什么?

php artisan queue:work --queue=high,default

但是如果连接的queue参数的值不高,则此代码将永远无法工作

默认队列驱动程序
'default' => env('QUEUE_DRIVER', 'database'),

队列连接
'connections' => [

'Register' => [
'driver' => 'database',
'table' => 'tbljobs',
'queue' => 'low',
'retry_after' => 5,
],

'ForgotPassword' => [
'driver' => 'database',
'table' => 'tbljobs',
'queue' => 'low',
'retry_after' => 5,
],

],

.env
QUEUE_DRIVER=Register

注册电子邮件的 Controller 代码
$job = (new SendActivationEmail($Data))
->onConnection('Register');
dispatch($job);

重置密码的 Controller 代码
$job = (new SendResetPasswordEmail($this->tokens->create($user), $user))
->onConnection('ForgotPassword');
dispatch($job);

最佳答案

注意连接Vs。队列Laravel's queue documentation中的注释,据我所知,该注释适用于SQS以外的所有队列驱动程序。

Before getting started with Laravel queues, it is important to understand the distinction between "connections" and "queues". In your config/queue.php configuration file, there is a connections configuration option. This option defines a particular connection to a backend service such as Amazon SQS, Beanstalk, or Redis. However, any given queue connection may have multiple "queues" which may be thought of as different stacks or piles of queued jobs.

Note that each connection configuration example in the queue configuration file contains a queue attribute. This is the default queue that jobs will be dispatched to when they are sent to a given connection. In other words, if you dispatch a job without explicitly defining which queue it should be dispatched to, the job will be placed on the queue that is defined in the queue attribute of the connection configuration:



实际上,您将在 config/queues.php文件中注册一个队列连接,并且如果未提供另一个队列,则 default参数将简单地是默认情况下将作业调度到的队列。

Vitaly的上述答案将是解决问题的正确方法(合并为具有默认队列的单个连接),然后根据需要调整作业以发送到不同的队列。这是队列配置如何工作的一些重要(我认为)上下文。

关于laravel - 如何使用队列设置高,低和中优先级的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42325247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com