Skip to main content
Laravel’s queue event system is driver-agnostic. The events are emitted by the Laravel Queue Worker itself, not by the underlying driver (MongoDB, Redis, SQS, etc.). This means the exact same event listener class you used for your MongoDB queue will work perfectly with your Redis queue without any changes to the listener’s logic. You just need to switch your queue driver in your configuration. Let’s break down how it works and provide a full example implementation.

The Core Concept: The Emitter is the Worker

You don’t need to create an “emitter.” The Laravel queue worker (php artisan queue:work) is the component that does the emitting. Its process looks like this:
  1. Fetch Job: The worker asks the configured queue driver (e.g., Redis) for the next available job.
  2. Emit JobProcessing: Before executing the job, the worker fires the Illuminate\Queue\Events\JobProcessing event.
  3. Execute Job: The worker calls the handle() method on your job class.
  4. Handle Outcome:
  • Success: If the handle() method completes without an exception, the worker fires the Illuminate\Queue\Events\JobProcessed event and deletes the job from the queue.
  • Failure: If the handle() method throws an exception, the worker fires Illuminate\Queue\Events\JobExceptionOccurred. If the job has exhausted all its retries, it then fires Illuminate\Queue\Events\JobFailed.
This entire flow is the same no matter which driver is being used.

Example Implementation: Listener for a Redis Queue

Let’s build a complete, practical example for monitoring and logging queue jobs using Redis.

Step 1: Configure Laravel to Use Redis for Queues

First, ensure your .env file is set up to use Redis as the queue connection. .env
You’ll also need to have the predis/predis or phpredis extension installed. composer require predis/predis

Step 2: Create a Job to Dispatch

Let’s create a sample job. This job will be the “payload” that gets processed.
Now, let’s edit the job to accept some data and log a message. app/Jobs/ProcessOrder.job
(Note: This assumes you have an Order model. You can replace Order $order with a simple integer like int $orderId for testing purposes.)

Step 3: Create the Event Listener (The Subscriber)

Instead of creating one listener per event, it’s often cleaner to create a “Subscriber” class that listens for multiple queue-related events.
Now, let’s modify this class to listen for the key queue events and log useful information. app/Listeners/QueueEventSubscriber.php
(I’ve also added a custom queue log channel for clarity. You can configure this in config/logging.php or just let it write to the default log file.)

Step 4: Register the Subscriber

Now, we need to tell Laravel about our subscriber class. app/Providers/EventServiceProvider.php

Step 5: Test It Out!

  1. Dispatch the job from a route, controller, or Tinker:
  1. Run the queue worker in your terminal:
  1. Check your log file (storage/logs/laravel.log or your custom queue log). You will see the output from your subscriber:
On Success:
On Failure (if you uncomment the throw new \Exception(...) line):

Conclusion

As you can see, the implementation of the emitter (the queue worker) and the listener (QueueEventSubscriber) is completely independent of the queue driver. Your existing logic for logging and monitoring will work seamlessly when you switch QUEUE_CONNECTION from mongodb to redis. This is one of the most powerful features of Laravel’s abstraction layers.