PHPackages                             girni/laravel-rabbitmq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. girni/laravel-rabbitmq

ActiveLibrary[Queues &amp; Workers](/categories/queues)

girni/laravel-rabbitmq
======================

Laravel RabbitMQ package that extends https://github.com/vyuldashev/laravel-queue-rabbitmq to support microservice communication.

1.0.0(2y ago)0114MITPHPPHP &gt;=8.0

Since Jan 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/girni/laravel-rabbitmq)[ Packagist](https://packagist.org/packages/girni/laravel-rabbitmq)[ RSS](/packages/girni-laravel-rabbitmq/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel RabbitMQ package that extends  to support microservice communication.

Installation
------------

[](#installation)

```
composer require girni/laravel-rabbitmq
```

In your `composer.json` file add these lines of codes under `require` section and `repositories`:

```
{
  "require": {
    "girni/laravel-rabbitmq": "^1.0"
  }
}
```

After that changes simply run `composer install` or `composer update girni/laravel-rabbitmq` to make it installed.

The package will automatically register itself.

Add connection to `config/queue.php`:

```
'connections' => [
    // ...
    'rabbitmq' => [

       'driver' => 'rabbitmq',
       'queue' => env('RABBITMQ_QUEUE', 'default'),
       'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,

       'hosts' => [
           [
               'host' => env('RABBITMQ_HOST', '127.0.0.1'),
               'port' => env('RABBITMQ_PORT', 5672),
               'user' => env('RABBITMQ_USER', 'guest'),
               'password' => env('RABBITMQ_PASSWORD', 'guest'),
               'vhost' => env('RABBITMQ_VHOST', '/'),
           ],
       ],

       'options' => [
           'ssl_options' => [
               'cafile' => env('RABBITMQ_SSL_CAFILE', null),
               'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
               'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
               'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
               'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
           ],
           'queue' => [
               'job' => Girni\LaravelRabbitMQ\LaravelRabbitMQJobHandler::class,
           ],
       ],

       /*
        * Set to "horizon" if you wish to use Laravel Horizon.
        */
       'worker' => env('RABBITMQ_WORKER', Girni\LaravelRabbitMQ\Queue\RabbitMQQueue::class),

    ],
    // ...
],
```

Publish `laravel-rabbitmq.php` config file:

```
php artisan vendor:publish --provider="Girni\LaravelRabbitMQ\LaravelRabbitMQServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

Define a queue in .env file
---------------------------

[](#define-a-queue-in-env-file)

To ensure that our communication between applications runs smoothly, it is necessary to define separate queues for each application. We can do it in `.env` file.

```
RABBITMQ_QUEUE=my-application-queue
```

Defining a `RABBIT_QUEUE` will result that our application will consume a messages only from that queue. By making different queues for each application we have guarantee our messages won't be processed in incorrect way by other application.

### Creating producer

[](#creating-producer)

Producing means nothing more than sending. A class that sends messages is a producer. Our producer classess should be as simple as it's only possible. It should contains a message data passed by it's constructor and the `::name()` that must be implemented due to implemented contract.

`::name()` value is very important, it's being used to recognize which consumer we should run to handle the produced message.

```
