PHPackages                             edcpl/laravel-queue-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. edcpl/laravel-queue-rabbitmq

ActiveLibrary

edcpl/laravel-queue-rabbitmq
============================

RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.

0.0.1(3y ago)0323MITPHPPHP ^8.0

Since Jan 3Pushed 3y agoCompare

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

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

RabbitMQ Queue driver for Laravel
=================================

[](#rabbitmq-queue-driver-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/ae35fda6d3cb5b57b8d37357c6952383168d3700e346429ed5246210f4b05a48/68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)[![Build Status](https://github.com/vyuldashev/laravel-queue-rabbitmq/workflows/Tests/badge.svg)](https://github.com/vyuldashev/laravel-queue-rabbitmq/actions)[![Total Downloads](https://camo.githubusercontent.com/f38a16fd27cfaa1a90e2c6bca3d4b04a9e5d73abb89d388dabc6e4c86354c4bc/68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)[![StyleCI](https://camo.githubusercontent.com/f60d931ca9314100ec128218fd0d3600c6dcc6517471a84b280d9b4fd511dcbc/68747470733a2f2f7374796c6563692e696f2f7265706f732f31343937363735322f736869656c64)](https://styleci.io/repos/14976752)[![License](https://camo.githubusercontent.com/5d5fd5b6ae3ea751391bfefbbb234e670205414b1ec2a8e06f789a9ee277ea6b/68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)

Support Policy
--------------

[](#support-policy)

Only the latest version will get new features. Bug fixes will be provided using the following scheme:

Package VersionLaravel VersionBug Fixes Until139August 8th, 2023[Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md)Installation
------------

[](#installation)

You can install this package via composer using this command:

```
composer require vladimir-yuldashev/laravel-queue-rabbitmq

```

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' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
           ],
       ],

       /*
        * Set to "horizon" if you wish to use Laravel Horizon.
        */
       'worker' => env('RABBITMQ_WORKER', 'default'),
       'after_commit' => false,
    ],

    // ...
],
```

### Optional Config

[](#optional-config)

Optionally add queue options to the config of a connection. Every queue created for this connection, get's the properties.

When you want to prioritize messages when they were delayed, then this is possible by adding extra options.

- When max-priority is omitted, the max priority is set with 2 when used.

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

    'rabbitmq' => [
        // ...

        'options' => [
            'queue' => [
                // ...

                'prioritize_delayed' =>  false,
                'queue_max_priority' => 10,
            ],
        ],
    ],

    // ...
],
```

When you want to publish messages against an exchange with routing-key's, then this is possible by adding extra options.

- When the exchange is omitted, RabbitMQ will use the `amq.direct` exchange for the routing-key
- When routing-key is omitted the routing-key by default is the `queue` name.
- When using `%s` in the routing-key the queue\_name will be substituted.

> Note: when using exchange with routing-key, u probably create your queues with bindings yourself.

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

    'rabbitmq' => [
        // ...

        'options' => [
            'queue' => [
                // ...

                'exchange' => 'application-x',
                'exchange_type' => 'topic',
                'exchange_routing_key' => '',
            ],
        ],
    ],

    // ...
],
```

In Laravel failed jobs are stored into the database. But maybe you want to instruct some other process to also do something with the message. When you want to instruct RabbitMQ to reroute failed messages to a exchange or a specific queue, then this is possible by adding extra options.

- When the exchange is omitted, RabbitMQ will use the `amq.direct` exchange for the routing-key
- When routing-key is omitted, the routing-key by default the `queue` name is substituted with `'.failed'`.
- When using `%s` in the routing-key the queue\_name will be substituted.

> Note: When using failed\_job exchange with routing-key, u probably need to create your exchange/queue with bindings yourself.

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

    'rabbitmq' => [
        // ...

        'options' => [
            'queue' => [
                // ...

                'reroute_failed' => true,
                'failed_exchange' => 'failed-exchange',
                'failed_routing_key' => 'application-x.%s',
            ],
        ],
    ],

    // ...
],
```

### Use your own RabbitMQJob class

[](#use-your-own-rabbitmqjob-class)

Sometimes you have to work with messages published by another application.
Those messages probably won't respect Laravel's job payload schema. The problem with these messages is that, Laravel workers won't be able to determine the actual job or class to execute.

You can extend the build-in `RabbitMQJob::class` and within the queue connection config, you can define your own class. When you specify an `job` key in the config, with your own class name, every message retrieved from the broker will get wrapped by your own class.

An example for the config:

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

    'rabbitmq' => [
        // ...

        'options' => [
            'queue' => [
                // ...

                'job' => \App\Queue\Jobs\RabbitMQJob::class,
            ],
        ],
    ],

    // ...
],
```

An example of your own job class:

```
