{"id":15036329,"url":"https://github.com/vyuldashev/laravel-queue-rabbitmq","last_synced_at":"2025-12-17T20:33:20.511Z","repository":{"id":12336138,"uuid":"14976752","full_name":"vyuldashev/laravel-queue-rabbitmq","owner":"vyuldashev","description":"RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.","archived":false,"fork":false,"pushed_at":"2025-04-24T16:48:06.000Z","size":612,"stargazers_count":2001,"open_issues_count":27,"forks_count":422,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-05-09T00:55:22.094Z","etag":null,"topics":["amqp","horizon","laravel","php","queue","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vyuldashev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG-10x.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-12-06T07:41:08.000Z","updated_at":"2025-05-08T18:30:32.000Z","dependencies_parsed_at":"2024-03-12T21:30:14.388Z","dependency_job_id":"1c072b70-7135-4e97-977e-5cc2bacdc667","html_url":"https://github.com/vyuldashev/laravel-queue-rabbitmq","commit_stats":{"total_commits":485,"total_committers":70,"mean_commits":6.928571428571429,"dds":"0.39587628865979385","last_synced_commit":"d174b9575eea7dbf9025046f7b4a0cff02891e28"},"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyuldashev%2Flaravel-queue-rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyuldashev%2Flaravel-queue-rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyuldashev%2Flaravel-queue-rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyuldashev%2Flaravel-queue-rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vyuldashev","download_url":"https://codeload.github.com/vyuldashev/laravel-queue-rabbitmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448578,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqp","horizon","laravel","php","queue","rabbitmq"],"created_at":"2024-09-24T20:30:49.059Z","updated_at":"2025-12-17T20:33:15.468Z","avatar_url":"https://github.com/vyuldashev.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"RabbitMQ Queue driver for Laravel\n======================\n[![Latest Stable Version](https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/v/stable?format=flat-square)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)\n[![Build Status](https://github.com/vyuldashev/laravel-queue-rabbitmq/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/vyuldashev/laravel-queue-rabbitmq/actions/workflows/tests.yml)\n[![Total Downloads](https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/downloads?format=flat-square)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)\n[![License](https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/license?format=flat-square)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)\n\n## Support Policy\n\nOnly the latest version will get new features. Bug fixes will be provided using the following scheme:\n\n| Package Version | Laravel Version | Bug Fixes Until  |                                                                                             |\n|-----------------|-----------------|------------------|---------------------------------------------------------------------------------------------|\n| 13              | 9               | August 8th, 2023 | [Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md) |\n\n## Installation\n\nYou can install this package via composer using this command:\n\n```\ncomposer require vladimir-yuldashev/laravel-queue-rabbitmq\n```\n\nThe package will automatically register itself.\n\n### Configuration\n\nAdd connection to `config/queue.php`:\n\n\u003e This is the minimal config for the rabbitMQ connection/driver to work.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n    \n       'driver' =\u003e 'rabbitmq',\n       'hosts' =\u003e [\n           [\n               'host' =\u003e env('RABBITMQ_HOST', '127.0.0.1'),\n               'port' =\u003e env('RABBITMQ_PORT', 5672),\n               'user' =\u003e env('RABBITMQ_USER', 'guest'),\n               'password' =\u003e env('RABBITMQ_PASSWORD', 'guest'),\n               'vhost' =\u003e env('RABBITMQ_VHOST', '/'),\n           ],\n           // ...\n       ],\n\n       // ...\n    ],\n\n    // ...    \n],\n```\n\n### Optional Queue Config\n\nOptionally add queue options to the config of a connection.\nEvery queue created for this connection, gets the properties.\n\nWhen you want to prioritize messages when they were delayed, then this is possible by adding extra options.\n\n- When max-priority is omitted, the max priority is set with 2 when used.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'options' =\u003e [\n            'queue' =\u003e [\n                // ...\n\n                'prioritize_delayed' =\u003e  false,\n                'queue_max_priority' =\u003e 10,\n            ],\n        ],\n    ],\n\n    // ...    \n],\n```\n\nWhen you want to publish messages against an exchange with routing-keys, then this is possible by adding extra options.\n\n- When the exchange is omitted, RabbitMQ will use the `amq.direct` exchange for the routing-key\n- When routing-key is omitted the routing-key by default is the `queue` name.\n- When using `%s` in the routing-key the queue_name will be substituted.\n\n\u003e Note: when using an exchange with routing-key, you probably create your queues with bindings yourself.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'options' =\u003e [\n            'queue' =\u003e [\n                // ...\n\n                'exchange' =\u003e 'application-x',\n                'exchange_type' =\u003e 'topic',\n                'exchange_routing_key' =\u003e '',\n            ],\n        ],\n    ],\n\n    // ...    \n],\n```\n\nIn Laravel failed jobs are stored into the database. But maybe you want to instruct some other process to also do\nsomething with the message.\nWhen you want to instruct RabbitMQ to reroute failed messages to a exchange or a specific queue, then this is possible\nby adding extra options.\n\n- When the exchange is omitted, RabbitMQ will use the `amq.direct` exchange for the routing-key\n- When routing-key is omitted, the routing-key by default the `queue` name is substituted with `'.failed'`.\n- When using `%s` in the routing-key the queue_name will be substituted.\n\n\u003e Note: When using failed_job exchange with routing-key, you probably need to create your exchange/queue with bindings\n\u003e yourself.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'options' =\u003e [\n            'queue' =\u003e [\n                // ...\n\n                'reroute_failed' =\u003e true,\n                'failed_exchange' =\u003e 'failed-exchange',\n                'failed_routing_key' =\u003e 'application-x.%s',\n            ],\n        ],\n    ],\n\n    // ...    \n],\n```\n\n### Horizon support\n\nStarting with 8.0, this package supports [Laravel Horizon](https://laravel.com/docs/horizon) out of the box. Firstly,\ninstall Horizon and then set `RABBITMQ_WORKER` to `horizon`.\n\nHorizon is depending on events dispatched by the worker.\nThese events inform Horizon what was done with the message/job.\n\nThis Library supports Horizon, but in the config you have to inform Laravel to use the QueueApi compatible with horizon.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        /* Set to \"horizon\" if you wish to use Laravel Horizon. */\n       'worker' =\u003e env('RABBITMQ_WORKER', 'default'),\n    ],\n\n    // ...    \n],\n```\n\n### Use your own RabbitMQJob class\n\nSometimes you have to work with messages published by another application.  \nThose messages probably won't respect Laravel's job payload schema.\nThe problem with these messages is that, Laravel workers won't be able to determine the actual job or class to execute.\n\nYou can extend the build-in `RabbitMQJob::class` and within the queue connection config, you can define your own class.\nWhen you specify a `job` key in the config, with your own class name, every message retrieved from the broker will get\nwrapped by your own class.\n\nAn example for the config:\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'options' =\u003e [\n            'queue' =\u003e [\n                // ...\n\n                'job' =\u003e \\App\\Queue\\Jobs\\RabbitMQJob::class,\n            ],\n        ],\n    ],\n\n    // ...    \n],\n```\n\nAn example of your own job class:\n\n```php\n\u003c?php\n\nnamespace App\\Queue\\Jobs;\n\nuse VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob as BaseJob;\n\nclass RabbitMQJob extends BaseJob\n{\n\n    /**\n     * Fire the job.\n     *\n     * @return void\n     */\n    public function fire()\n    {\n        $payload = $this-\u003epayload();\n\n        $class = WhatheverClassNameToExecute::class;\n        $method = 'handle';\n\n        ($this-\u003einstance = $this-\u003eresolve($class))-\u003e{$method}($this, $payload);\n\n        $this-\u003edelete();\n    }\n}\n\n```\n\nOr maybe you want to add extra properties to the payload:\n\n```php\n\u003c?php\n\nnamespace App\\Queue\\Jobs;\n\nuse VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob as BaseJob;\n\nclass RabbitMQJob extends BaseJob\n{\n   /**\n     * Get the decoded body of the job.\n     *\n     * @return array\n     */\n    public function payload()\n    {\n        return [\n            'job'  =\u003e 'WhatheverFullyQualifiedClassNameToExecute@handle',\n            'data' =\u003e json_decode($this-\u003egetRawBody(), true)\n        ];\n    }\n}\n```\n\nIf you want to handle raw message, not in JSON format or without 'job' key in JSON,\nyou should add stub for `getName` method:\n\n```php\n\u003c?php\n\nnamespace App\\Queue\\Jobs;\n\nuse Illuminate\\Support\\Facades\\Log;\nuse VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob as BaseJob;\n\nclass RabbitMQJob extends BaseJob\n{\n    public function fire()\n    {\n        $anyMessage = $this-\u003egetRawBody();\n        Log::info($anyMessage);\n\n        $this-\u003edelete();\n    }\n\n    public function getName()\n    {\n        return '';\n    }\n}\n```\n\n### Use your own Connection\n\nYou can extend the built-in `PhpAmqpLib\\Connection\\AMQPStreamConnection::class`\nor `PhpAmqpLib\\Connection\\AMQPSLLConnection::class` and within the connection config, you can define your own class.\nWhen you specify a `connection` key in the config, with your own class name, every connection will use your own class.\n\nAn example for the config:\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'connection' = \u003e \\App\\Queue\\Connection\\MyRabbitMQConnection::class,\n    ],\n\n    // ...    \n],\n```\n\n### Use your own Worker class\n\nIf you want to use your own `RabbitMQQueue::class` this is possible by\nextending `VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\RabbitMQQueue`.\nand inform laravel to use your class by setting `RABBITMQ_WORKER` to `\\App\\Queue\\RabbitMQQueue::class`.\n\n\u003e Note: Worker classes **must** extend `VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\RabbitMQQueue`\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        /* Set to a class if you wish to use your own. */\n       'worker' =\u003e \\App\\Queue\\RabbitMQQueue::class,\n    ],\n\n    // ...    \n],\n```\n\n```php\n\u003c?php\n\nnamespace App\\Queue;\n\nuse VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\RabbitMQQueue as BaseRabbitMQQueue;\n\nclass RabbitMQQueue extends BaseRabbitMQQueue\n{\n    // ...\n}\n```\n\n**For Example: A reconnect implementation.**\n\nIf you want to reconnect to RabbitMQ, if the connection is dead.\nYou can override the publishing and the createChannel methods.\n\n\u003e Note: this is not best practice, it is an example.\n\n```php\n\u003c?php\n\nnamespace App\\Queue;\n\nuse PhpAmqpLib\\Exception\\AMQPChannelClosedException;\nuse PhpAmqpLib\\Exception\\AMQPConnectionClosedException;\nuse VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\RabbitMQQueue as BaseRabbitMQQueue;\n\nclass RabbitMQQueue extends BaseRabbitMQQueue\n{\n\n    protected function publishBasic($msg, $exchange = '', $destination = '', $mandatory = false, $immediate = false, $ticket = null): void\n    {\n        try {\n            parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);\n        } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {\n            $this-\u003ereconnect();\n            parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);\n        }\n    }\n\n    protected function publishBatch($jobs, $data = '', $queue = null): void\n    {\n        try {\n            parent::publishBatch($jobs, $data, $queue);\n        } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {\n            $this-\u003ereconnect();\n            parent::publishBatch($jobs, $data, $queue);\n        }\n    }\n\n    protected function createChannel(): AMQPChannel\n    {\n        try {\n            return parent::createChannel();\n        } catch (AMQPConnectionClosedException) {\n            $this-\u003ereconnect();\n            return parent::createChannel();\n        }\n    }\n}\n```\n\n### Default Queue\n\nThe connection does use a default queue with value 'default', when no queue is provided by laravel.\nIt is possible to change te default queue by adding an extra parameter in the connection config.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n            \n        'queue' =\u003e env('RABBITMQ_QUEUE', 'default'),\n    ],\n\n    // ...    \n],\n```\n\n### Heartbeat\n\nBy default, your connection will be created with a heartbeat setting of `0`.\nYou can alter the heartbeat settings by changing the config.\n\n```php\n\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'options' =\u003e [\n            // ...\n\n            'heartbeat' =\u003e 10,\n        ],\n    ],\n\n    // ...    \n],\n```\n\n### SSL Secure\n\nIf you need a secure connection to rabbitMQ server(s), you will need to add these extra config options.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'secure' = \u003e true,\n        'options' =\u003e [\n            // ...\n\n            'ssl_options' =\u003e [\n                'cafile' =\u003e env('RABBITMQ_SSL_CAFILE', null),\n                'local_cert' =\u003e env('RABBITMQ_SSL_LOCALCERT', null),\n                'local_key' =\u003e env('RABBITMQ_SSL_LOCALKEY', null),\n                'verify_peer' =\u003e env('RABBITMQ_SSL_VERIFY_PEER', true),\n                'passphrase' =\u003e env('RABBITMQ_SSL_PASSPHRASE', null),\n            ],\n        ],\n    ],\n\n    // ...    \n],\n```\n\n### Events after Database commits\n\nTo instruct Laravel workers to dispatch events after all database commits are completed.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'after_commit' =\u003e true,\n    ],\n\n    // ...    \n],\n```\n\n### Lazy Connection\n\nBy default, your connection will be created as a lazy connection.\nIf for some reason you don't want the connection lazy you can turn it off by setting the following config.\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'lazy' = \u003e false,\n    ],\n\n    // ...    \n],\n```\n\n### Network Protocol\n\nBy default, the network protocol used for connection is tcp.\nIf for some reason you want to use another network protocol, you can add the extra value in your config options.\nAvailable protocols : `tcp`, `ssl`, `tls`\n\n```php\n'connections' =\u003e [\n    // ...\n\n    'rabbitmq' =\u003e [\n        // ...\n\n        'network_protocol' =\u003e 'tcp',\n    ],\n\n    // ...    \n],\n```\n\n### Octane support\n\nStarting with 13.3.0, this package supports [Laravel Octane](https://laravel.com/docs/octane) out of the box.\nFirstly, install Octane and don't forget to warm 'rabbitmq' connection in the octane config.\n\u003e See: https://github.com/vyuldashev/laravel-queue-rabbitmq/issues/460#issuecomment-1469851667\n\n## Laravel Usage\n\nOnce you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not\nneed to change anything else. If you do not know how to use the Queue API, please refer to the official Laravel\ndocumentation: http://laravel.com/docs/queues\n\n## Lumen Usage\n\nFor Lumen usage the service provider should be registered manually as follow in `bootstrap/app.php`:\n\n```php\n$app-\u003eregister(VladimirYuldashev\\LaravelQueueRabbitMQ\\LaravelQueueRabbitMQServiceProvider::class);\n```\n\n## Consuming Messages\n\nThere are two ways of consuming messages.\n\n1. `queue:work` command which is Laravel's built-in command. This command utilizes `basic_get`. Use this if you want to consume multiple queues.\n\n2. `rabbitmq:consume` command which is provided by this package. This command utilizes `basic_consume` and is more performant than `basic_get` by ~2x, but does not support multiple queues.\n\n## Testing\n\nSetup RabbitMQ using `docker-compose`:\n\n```bash\ndocker compose up -d\n```\n\nTo run the test suite you can use the following commands:\n\n```bash\n# To run both style and unit tests.\ncomposer test\n\n# To run only style tests.\ncomposer test:style\n\n# To run only unit tests.\ncomposer test:unit\n```\n\nIf you receive any errors from the style tests, you can automatically fix most,\nif not all the issues with the following command:\n\n```bash\ncomposer fix:style\n```\n\n## Contribution\n\nYou can contribute to this package by discovering bugs and opening issues. Please, add to which version of package you\ncreate pull request or issue. (e.g. [5.2] Fatal error on delayed job)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvyuldashev%2Flaravel-queue-rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvyuldashev%2Flaravel-queue-rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvyuldashev%2Flaravel-queue-rabbitmq/lists"}