Use Quorum Queues and Max Priority
mastermax-priority option. This allows you to leverage RabbitMQ's high-availability queue type and priority-based job processing.repository·master·Indexed 24 days ago
https://github.com/vyuldashev/laravel-queue-rabbitmqA RabbitMQ Queue driver for Laravel and Lumen that allows developers to use RabbitMQ as a backend for Laravel's queue system. It supports standard Laravel Queue API, Laravel Horizon, Quorum Queues, and custom job/connection/worker classes. Includes specialized CLI commands such as rabbitmq:consume for high-performance message consumption and rabbitmq:exchange-declare for managing exchanges.
max-priority option. This allows you to leverage RabbitMQ's high-availability queue type and priority-based job processing.If you need to process messages from other applications that do not follow Laravel's job payload schema, you can extend RabbitMQJob::class and specify your custom class in the options.queue.job config key.
Common use cases:
payload() to change how the job data is decoded.getName() to return an empty string if the message is not in a standard format.fire() to manually resolve and execute classes.// Config example
'rabbitmq' => [
'options' => [
'queue' => [
'job' => \App\Queue\Jobs\RabbitMQJob::class,
],
],
],
// Custom Job implementation example
namespace App\Queue\Jobs;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob;
class RabbitMQJob extends BaseJob
{
public function fire()
{
$payload = $this->payload();
$class = WhatheverClassNameToExecute::class;
$method = 'handle';
($this->instance = $this->resolve($class))->{$method}($this, $payload);
$this->delete();
}
}There are two ways to consume messages from RabbitMQ:
php artisan queue:work: Laravel's built-in command. It uses the basic_get protocol. Use this if you need to consume from multiple queues simultaneously.
php artisan rabbitmq:consume: A command provided by this package. It uses the basic_consume protocol and is approximately 2x more performant than basic_get, but it does not support consuming multiple queues at once.
To run tests, first ensure RabbitMQ is running via Docker Compose:
docker compose up -dThen use the following Composer commands:
composer test: Runs both style and unit tests.composer test:style: Runs only style tests.composer test:unit: Runs only unit tests.composer fix:style: Automatically fixes most style issues found by the style tests.docker compose up -d
# Test commands
composer test
composer test:style
composer test:unit
composer fix:styleFor Lumen applications, you must manually register the service provider in bootstrap/app.php:
$app->register(VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class);Install the package via Composer. The package will automatically register itself within your Laravel application.
composer require vladimir-yuldashev/laravel-queue-rabbitmqTo use Laravel Horizon, install Horizon and set the worker key in your RabbitMQ connection configuration to 'horizon'. This informs Laravel to use the QueueApi compatible with Horizon.
'rabbitmq' => [
// ...
/* Set to "horizon" if you wish to use Laravel Horizon. */
'worker' => env('RABBITMQ_WORKER', 'default'),
],You can prioritize messages when they are delayed by adding prioritize_delayed and queue_max_priority to the options.queue configuration. If queue_max_priority is omitted, it defaults to 2 when used.
'rabbitmq' => [
// ...
'options' => [
'queue' => [
// ...
'prioritize_delayed' => false,
'queue_max_priority' => 10,
],
],
],Control how the connection is established using these keys:
network_protocol: The protocol used (e.g., tcp, ssl, tls). Default is tcp.lazy: Boolean to enable/disable lazy connections. Default is true.after_commit: Boolean to instruct workers to dispatch events only after database commits are completed.'rabbitmq' => [
'network_protocol' => 'tcp',
'lazy' => false,
'after_commit' => true,
],The RabbitMQJob class implements Laravel's Illuminate\Contracts\Queue\Job contract. It wraps a PhpAmqpLib\Message\AMQPMessage and provides methods to manage the job lifecycle within RabbitMQ, such as delete() (which acknowledges the message), release() (which re-publishes the message with a delay), and markAsFailed() (which rejects the message).
If you are extending the driver or implementing custom logic, you can interact with these methods to control how RabbitMQ handles the message lifecycle (e.g., triggering Dead Letter Exchanges via reject during markAsFailed).
Adjust connection stability and performance using the following options keys:
heartbeat: Sets the heartbeat interval (default is 0).connection_timeout: Connection timeout in seconds (float).read_timeout: Read timeout in seconds (float).write_timeout: Write timeout in seconds (float).channel_rpc_timeout: Channel RPC timeout in seconds (float).'rabbitmq' => [
'options' => [
'heartbeat' => 10,
'connection_timeout' => 3.0,
'read_timeout' => 3.0,
'write_timeout' => 3.0,
'channel_rpc_timeout' => 0.0,
],
],