Skip to main content

Multiple Queues and Priority Jobs

Premium
3 min read

In this lesson, we'll learn about multiple queues and how to set job priorities. Sometimes, certain jobs are more important than others and need to be processed first, even if they were dispatched later.

Think of a real-life traffic scenario: cars are waiting at a traffic light, but an ambulance needs to pass through. Everyone moves aside to let the ambulance go first because it's a priority. We can implement similar priority rules with Laravel queues.


Dispatching Laravel Jobs To Different Queues

Let's look at a scenario where a user registers and triggers three different jobs. We want the last job to be processed before the other two:

use App\Jobs\CreateFirstTask;
use App\Jobs\SendWelcomeMessage;
use App\Jobs\SendRegisteredUserNotification;
 
class RegisteredUserController extends Controller
{
// ...
 
public function store(Request $request): RedirectResponse
{
// ...
 
CreateFirstTask::dispatch($user->id);
SendWelcomeMessage::dispatch($user->id);
SendRegisteredUserNotification::dispatch($user);
 
Auth::login($user);
 
return redirect(route('dashboard', absolute: false));
}
}

To make the third job a priority, we can place it in a separate queue by using...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

E
edolabera ✓ Link copied!

What happen if we have 'default' and 'priority' queue, but we only run php artisan queue:work without specifying queue option?

M
Modestas ✓ Link copied!

It will use the default queue, but it will not complete jobs from the priority

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.