Laravel Tutorials

Boosting Queue Management with Laravel's JobQueueing Event

Published
Boosting Queue Management with Laravel's JobQueueing Event image

Laravel's queue system has become even more powerful with the new JobQueueing event. This pre-dispatch hook creates fresh opportunities for job monitoring and manipulation right before they enter your queue system.

The event-driven architecture of Laravel's queue system already offers several lifecycle hooks like JobProcessing and JobProcessed. The JobQueueing event extends this capability by allowing access to an earlier phase - precisely when a job is about to be sent to your queue provider.

Here's a simple implementation of this new event:

use Illuminate\Queue\Events\JobQueueing;
use Illuminate\Support\Facades\Event;

// Register a listener for the JobQueueing event
Event::listen(function (JobQueueing $event) {
    // Extract information about the queuing job
    $job = $event->job;
    $connectionName = $event->connectionName;
    $payload = $event->payload;
    
    // Execute pre-queue logic here
});

This functionality opens up numerous practical applications for queue management and monitoring. For instance, you could implement environment-specific queue logging:

<?php

namespace App\Providers;

use Illuminate\Queue\Events\JobQueueing;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Log;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // Create a local development job logger
        Event::listen(function (JobQueueing $event) {
            if (app()->environment('local')) {
                Log::info('Queueing job', [
                    'job' => get_class($event->job),
                    'connection' => $event->connectionName,
                    'queue' => $event->payload['queue'] ?? 'default'
                ]);
            }
        });
    }
}

This approach allows teams to build comprehensive queue activity dashboards or implement specialized logic that needs to execute just before jobs enter the queue system. You could extend this to add custom metadata to jobs, enforce rate limiting for specific job types, or dynamically redirect jobs to different queues based on system load.

Harris Raftopoulos photo

Senior Software Engineer • Staff & Educator @ Laravel News • Co-organizer @ Laravel Greece Meetup

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Generate Laravel Validation Rules From a JSON Schema image

Generate Laravel Validation Rules From a JSON Schema

Read article
Laravel Suspicious Login: Detect and Block Risky Logins image

Laravel Suspicious Login: Detect and Block Risky Logins

Read article
Decide with Jev: Make Failed AI Requests Safe in Laravel image

Decide with Jev: Make Failed AI Requests Safe in Laravel

Read article
Black Friday: Learn the habits behind AI workflows that work image

Black Friday: Learn the habits behind AI workflows that work

Read article
Laravel Black Friday and Cyber Monday Deals 2026 image

Laravel Black Friday and Cyber Monday Deals 2026

Read article
pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux image

pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux

Read article