{"id":37007668,"url":"https://github.com/kunalvarma05/laravel-rabbitmq","last_synced_at":"2026-01-14T00:49:11.921Z","repository":{"id":37863498,"uuid":"242348127","full_name":"kunalvarma05/laravel-rabbitmq","owner":"kunalvarma05","description":"🐰 An easy to use Laravel package for working with RabbitMQ.","archived":false,"fork":false,"pushed_at":"2023-12-11T05:49:46.000Z","size":349,"stargazers_count":18,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-05T15:18:37.526Z","etag":null,"topics":["laravel","php","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/kunalvarma05.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-22T13:40:50.000Z","updated_at":"2024-03-10T06:18:49.000Z","dependencies_parsed_at":"2022-08-18T17:01:14.521Z","dependency_job_id":null,"html_url":"https://github.com/kunalvarma05/laravel-rabbitmq","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/kunalvarma05/laravel-rabbitmq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalvarma05%2Flaravel-rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalvarma05%2Flaravel-rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalvarma05%2Flaravel-rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalvarma05%2Flaravel-rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kunalvarma05","download_url":"https://codeload.github.com/kunalvarma05/laravel-rabbitmq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalvarma05%2Flaravel-rabbitmq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["laravel","php","rabbitmq"],"created_at":"2026-01-14T00:49:11.068Z","updated_at":"2026-01-14T00:49:11.908Z","avatar_url":"https://github.com/kunalvarma05.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel RabbitMQ\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kunalvarma05/laravel-rabbitmq.svg?style=flat-square)](https://packagist.org/packages/kunalvarma05/laravel-rabbitmq)\n![Travis (.com)](https://img.shields.io/travis/com/kunalvarma05/laravel-rabbitmq?style=flat-square)\n![Coveralls github](https://img.shields.io/coveralls/github/kunalvarma05/laravel-rabbitmq?style=flat-square)\n[![StyleCI](https://github.styleci.io/repos/242348127/shield)](https://github.styleci.io/repos/242348127)\n[![Quality Score](https://img.shields.io/scrutinizer/g/kunalvarma05/laravel-rabbitmq.svg?style=flat-square)](https://scrutinizer-ci.com/g/kunalvarma05/laravel-rabbitmq)\n[![Total Downloads](https://img.shields.io/packagist/dt/kunalvarma05/laravel-rabbitmq.svg?style=flat-square)](https://packagist.org/packages/kunalvarma05/laravel-rabbitmq)\n\nAn easy-to-use Laravel package for working with RabbitMQ.\n\n## Features\n\n- Producers\n- Consumers\n- Publish / Subscribe\n- Exchanges\n  - Default\n  - Direct\n  - Topic\n  - Fanout\n\n## Requirements\n\n- PHP 7.4+\n- Laravel 6.0+\n\n## Setup\n\n### 1. Installation\n\n```sh\ncomposer require kunalvarma05/laravel-rabbitmq\n```\n\n### 2. Default Configuration\n\n```sh\nphp artisan vendor:publish --tag=config\n```\n\n## Quick Start\n\n### **Initialize**\n\nThere are multiple ways of initializing the library:\n\n```php\n// A. Direct instantiation\n$rabbitMQ = new RabbitMQManager(app());\n\n// B. Binding\n$rabbitMQ = app('rabbitmq');\n\n// C. Dependency injection (Controller, Command, Job, etc.)\npublic function __consturct(RabbitMQManager $rabbitMQ) { ... }\n\n// D. Facade\n// All the public methods of the `RabbitMQManager` class\n// are available through the `RabbitMQ` facade.\nRabbitMQ::getConnections();\n```\n\n### **Publish**\n\n```php\n$message = new RabbitMQMessage('message body');\n\n// Publish to the default exchange/topic/queue\n$rabbitMQ-\u003epublisher()-\u003epublish($message);\n\n// Publish bulk messages\n$messages = [new RabbitMQMessage('message 1'), new RabbitMQMessage('message 2')];\n$rabbitMQ-\u003epublisher()-\u003epublish($messages);\n```\n\n### **Consume**\n\n```php\n// A. Consume through a closure\n$handler = new RabbitMQGenericMessageConsume(function (RabbitMQIncomingMessage $message) {\n  $content = $message-\u003egetStream();\n});\n\n// B. Consume through a class\nclass MyMessageConsumer extends RabbitMQMessageConsumer {\n  public function handle(RabbitMQIncomingMessage $message) {\n    $content = $message-\u003egetStream();\n  }\n}\n$handler = new MyMessageConsumer();\n\n// Starts a blocking loop `while (true)`\n$rabbitMQ-\u003econsumer()-\u003econsume($handler);\n```\n\n### **Interact**\n\n```php\n// Resolve the default connection\n// @see: AMQPSSLConnection https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPSSLConnection.php\n$amqpConnection = $rabbitMQ-\u003eresolveConnection();\n\n// Resolve the default channel\n// @see: AMQPChannel https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php\n$amqpChannel = $rabbitMQ-\u003eresolveChannel();\n```\n\n### **Configuration**\n\n#### Connection Configuration\n\n```php\n$connectionName = 'custom_connection'; // Set to `null` for default connection\n// Override the default connection config\n$connectionConfig = new ConnectionConfig(['username' =\u003e 'quest', 'password' =\u003e 'quest']);\n$connectionConfig-\u003esetHost('localhost');\n$customConnection = $rabbitMQ-\u003eresolveConnection($connectionName, $connectionConfig);\n```\n\n#### Message Configuration\n\n```php\n$config = [\n  'content_encoding' =\u003e 'UTF-8',\n  'content_type'     =\u003e 'text/plain',\n  'delivery_mode'    =\u003e AMQPMessage::DELIVERY_MODE_PERSISTENT,\n];\n$message = new RabbitMQMessage('message body', $config);\n\n// Set message exchange\n$exchangeConfig = ['type' =\u003e AMQPExchangeType::DIRECT];\n$exchange = new RabbitMQExchange('my_exchange', $exchangeConfig);\n$message-\u003esetExchange($exchange);\n```\n\n#### Publish Configuration\n\n```php\n$publisher = $rabbitMQ-\u003epublisher();\n\n$message = new RabbitMQMessage('message body');\n\n$exchangeConfig = ['type' =\u003e AMQPExchangeType::TOPIC];\n$exchange = new RabbitMQExchange('my_exchange', $exchangeConfig);\n\n$message-\u003esetExchange($exchange);\n\n$routingKey = 'key'; // Can be an empty string, but not null\n$connectionName = 'custom_connection'; // Set to null for default connection\n\n// The publish config allows you to any override default configuration\n//\n// The following precendence works for the configuration:\n// Message exchange config \u003e Publish config \u003e Connection config \u003e Default config\n//\n// In this case, the exchange type used would be AMQPExchangeType::TOPIC\n$publishConfig = new PublishConfig(['exchange' =\u003e ['type' =\u003e AMQPExchangeType::FANOUT]]);\n\n$publisher-\u003epublish($message, $routingKey, $connectionName, $publishConfig);\n```\n\n#### Consumer Configuration\n\n```php\n$consumer = $rabbitMQ-\u003econsumer();\n$routingKey = 'key';\n\n$exchange = new RabbitMQExchange('test_exchange', ['declare' =\u003e true, 'durable' =\u003e true]);\n$queue = new RabbitMQQueue('my_queue', ['declare' =\u003e true, 'durable' =\u003e true]);\n\n$messageConsumer = new RabbitMQGenericMessageConsumer(\n    function (RabbitMQIncomingMessage $message) {\n      // Acknowledge a message\n      $message-\u003egetDelivery()-\u003eacknowledge();\n      // Reject a message\n      $requeue = true; // Reject and Requeue\n      $message-\u003egetDelivery()-\u003ereject($requeue);\n    },\n    $this,\n);\n\n// A1. Set the exchange and the queue directly\n$messageConsumer\n    -\u003esetExchange($exchange)\n    -\u003esetQueue($queue);\n\n// OR\n\n// A2. Set the exchange and the queue through config\n$consumeConfig = new ConsumeConfig(\n  [\n    'queue' =\u003e [\n      'name' =\u003e 'my_queue',\n      'declare' =\u003e true,\n      'durable' =\u003e true,\n  ],\n  'exchange' =\u003e [\n      'name' =\u003e 'test_exchange',\n      'declare' =\u003e true,\n    ],\n  ],\n);\n\n$consumer-\u003econsume(\n    $messageConsumer,\n    $routingKey,\n    null,\n    $consumeConfig,\n);\n```\n\n## **Example**\n\n### Running a Consumer\n\n- Create a custom command:\n\n```sh\nphp artisan make:command MyRabbitConsumer --command \"rabbitmq:my-consumer {--queue=} {--exchange=} {--routingKey=}\"\n```\n\n- Register the command in `app/Console/Kernel.php`\n\n```php\nprotected $commands = [\n  MyRabbitConsumer::class,\n];\n```\n\n- Consume through the handler\n\n```php\n\u003c?php\n\nnamespace App\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Kunnu\\RabbitMQ\\RabbitMQQueue;\nuse Kunnu\\RabbitMQ\\RabbitMQExchange;\nuse Kunnu\\RabbitMQ\\RabbitMQIncomingMessage;\nuse Kunnu\\RabbitMQ\\RabbitMQGenericMessageConsumer;\n\nclass MyRabbitConsumer extends Command\n{\n    /**\n     * The name and signature of the console command.\n     *\n     * @var string\n     */\n    protected $signature = 'rabbitmq:my-consumer {--queue} {--exchange} {--routingKey}';\n\n    /**\n     * The console command description.\n     *\n     * @var string\n     */\n    protected $description = 'My consumer command';\n\n    /**\n     * Create a new command instance.\n     *\n     * @return void\n     */\n    public function __construct()\n    {\n        parent::__construct();\n    }\n\n    /**\n     * Execute the console command.\n     *\n     * @return mixed\n     */\n    public function handle()\n    {\n        $rabbitMQ = app('rabbitmq');\n        $messageConsumer = new RabbitMQGenericMessageConsumer(\n            function (RabbitMQIncomingMessage $message) {\n                // Handle message\n                $this-\u003einfo($message-\u003egetStream()); // Print to console\n            },\n            $this, // Scope the closure to the command\n        );\n\n        $routingKey = $this-\u003eoption('routingKey') ?? '';\n        $queue = new RabbitMQQueue($this-\u003eoption('queue') ?? '', ['declare' =\u003e true]);\n        $exchange = new RabbitMQExchange($this-\u003eoption('exchange') ?? '', ['declare' =\u003e true]);\n\n        $messageConsumer\n            -\u003esetExchange($exchange)\n            -\u003esetQueue($queue);\n\n        $rabbitMQ-\u003econsumer()-\u003econsume($messageConsumer, $routingKey);\n    }\n}\n```\n\n- Call the command from the console\n\n```sh\nphp artisan rabbitmq:my-consumer --queue='my_queue' --exchange='test_exchange' --routingKey='key'\n```\n\n### Publishing Messages\n\n- Create route \u003c-\u003e controller binding\n\n```php\nRoute::get('/publish', 'MyRabbitMQController@publish');\n```\n\n- Create a controller to publish message\n\n```php\nclass MyRabbitMQController extends Controller {\n\n  public function publish(Request $request)\n  {\n    $rabbitMQ = app('rabbitmq');\n    $consumer = $rabbitMQ-\u003econsumer();\n    $routingKey = 'key'; // The key used by the consumer\n\n    // The exchange (name) used by the consumer\n    $exchange = new RabbitMQExchange('test_exchange', ['declare' =\u003e true]);\n\n    $contents = $request-\u003eget('message', 'random message');\n\n    $message = new RabbitMQMessage($contents);\n    $message-\u003esetExchange($exchange);\n\n    $rabbitMQ-\u003epublisher()-\u003epublish(\n        $message,\n        $routingKey\n    );\n\n    return ['message' =\u003e \"Published {$contents}\"];\n  }\n}\n```\n\n- Make a request or browse to: `http://localhost:8000/publish?message=Hello`\n\n- Check your console for the message `Hello` to be printed\n\n## Tests\n\n```php\ncomposer run-script test\n```\n\n## Credits\n\n- [Kunal Varma](https://github.com/kunalvarma05)\n- [All Contributors](https://github.com/kunalvarma05/laravel-rabbitmq/contributors)\n- [PHP AMQP Lib](https://github.com/php-amqplib/php-amqplib)\n- [PHP AMQ Package](https://github.com/ssi-anik/amqp)\n\n## License\n\nThe MIT License (MIT). Please see [License File](./LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunalvarma05%2Flaravel-rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkunalvarma05%2Flaravel-rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunalvarma05%2Flaravel-rabbitmq/lists"}