How to set high, low and medium priority email using queue?

You should have two queues defined in your config/queue.php file. Say, one with the name "high" and the other "low".

Then, you can then dispatch jobs to them as needed like this:

$job = (new SendResetPasswordEmail($this->tokens->create($user), $user))
        ->onConnection('ForgotPassword');
dispatch($job)->onQueue('high'));

Note: ->onQueue('high')

Finally, you would run: php artisan queue:work --queue=high,low

This will start a worker that will process all jobs on "high" queue before moving on to jobs on "low".


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.


'connections' => [

    'Register' => [ //<this name is connection name
        'driver'        =>  'database',
        'table'         =>  'tbljobs',
        'queue'         =>  'low',  //<this name is default queue name then you register a queue using this connection
        'retry_after'   =>  5,
    ],
],

I suggest you modify your code in the following way:

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

High priority job - Controller Code for Register email

$job = (new SendActivationEmail($Data))
        ->onConnection('Register')
        ->onQueue("high");
dispatch($job);

Medium priority job - Controller Code for Reset Password

$job = (new SendResetPasswordEmail($this->tokens->create($user), $user))
        ->onConnection('Register')
        ->onQueue("medium");
dispatch($job);

Low priority job

dispatch((new LowPriorityJob())->onQueue("low"));

Default priority job

dispatch((new DefaultPriorityJob()));

->onConnection('Register') //this line is usefull if you specify you default connection is Register in .env QUEUE_DRIVER=Register

Run your jobs

this command run your jobs stored in default connection. In your case Register

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

this command run your jobs stored in customConnectionName connection

php artisan queue:work customConnectionName --queue=high,medium,low,default

Try this

'connections' => [

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

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

],

AND then

php artisan queue:listen --queue=Register-high,Register-low