I am studying Job dispatching from here
I read that each connection has queue parameter which tell the queue name. Question is: How can I set the priority to send low or medium or high priority email?
I am using command: php artisan queue:listen to process job.
What I tried?
php artisan queue:work --queue=high,default
but this code never works if connection's queue parameter has value is not high
Default Queue Driver
'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, ], ],
Controller Code for Register email
$job = (new SendActivationEmail($Data)) ->onConnection('Register'); dispatch($job);
Controller Code for Reset Password
$job = (new SendResetPasswordEmail($this->tokens->create($user), $user)) ->onConnection('ForgotPassword'); dispatch($job);
Take note of the Connections Vs. Queues note in Laravel's queue documentation, which applies to all queue drivers apart from SQS as far as I'm aware.
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:
In effect you will register one queue connection in your
config/queues.php file and the
default parameter will simply be the queue that jobs are dispatched to by default, if another queue is not provided.
Vitaly's answer above would be the correct approach to the problem (consolidate to a single connection with a default queue) then adjust your jobs to get sent to different queues if required. This is some important (I think) context to how how queue configuration works.