Courses

Queues in Laravel 12

Multiple Queues and Priority Jobs

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Dispatching jobs to different queues using the onQueue() method
- Setting queue names in configuration with config/queue.php
- Running queue workers with priority order using --queue= flag
- Jobs in higher priority queues are processed before lower priority queues

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 15 lessons of this course? (46 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord