Failover Queue Driver in Laravel 12.34
- Failover Queue Driver
- How the Failover Queue Driver Works
- Defining a Failover Queue Connection
- Setting the Default Queue Connection
- When to Use the Failover Driver
- Summary
Failover Queue Driver
In Laravel 12.34, a new failover queue driver has been introduced to improve reliability when processing jobs. It allows you to define multiple queue connections in order of priority. If the first connection fails, Laravel automatically attempts to push the job to the next available connection.
This feature is particularly useful in production environments where uptime and job delivery are critical.
How the Failover Queue Driver Works
The failover driver acts as a wrapper around multiple queue connections. When a job is dispatched, Laravel will attempt to push it onto the first connection. If that connection fails, it will automatically try the next one in the list until it succeeds or exhausts all configured connections.
This ensures that jobs are not lost if the main queue system (e.g., Redis) goes down temporarily.
Defining a Failover Queue Connection
You can configure the failover driver in your config/queue.php file. Here’s a basic example:
'connections' => [ 'failover' => [ 'driver' => 'failover', 'connections' => [ 'redis', 'database', ], ], 'redis' => [ 'driver' => 'redis', 'connection' => 'default', 'queue' => env('REDIS_QUEUE', 'default'), 'retry_after' => 90, ], 'database' => [ 'driver' => 'database', 'table' => 'jobs', 'queue' => 'default', 'retry_after' => 90, ],],
In this example:
- Laravel will first try to push jobs to the Redis queue.
- If Redis is unavailable, it will fall back to the database queue.
Setting the Default Queue Connection
After defining your failover driver, you can set it as the default queue connection in your .env file:
QUEUE_CONNECTION=failover
This ensures all queued jobs will use the failover logic automatically.
When to Use the Failover Driver
The failover queue driver is ideal for:
- Applications where job reliability is essential.
- Systems with multiple queue backends (e.g., Redis, SQS, and database).
- High-availability environments where downtime of one queue system should not interrupt job processing.
Summary
Laravel’s failover queue driver ensures uninterrupted job dispatching by gracefully falling back to backup connections when the primary one fails. Configuring it takes only a few lines, yet it provides a significant boost in resilience for production applications.
For more details, refer to the official Laravel queue failover documentation and the framework pull request #57341.
Stay Updated.
I'll you email you as soon as new, fresh content is published.