PHPackages                             mscode-pl/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. [Queues &amp; Workers](/categories/queues)
4. /
5. mscode-pl/laravel-queue-rabbitmq

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

mscode-pl/laravel-queue-rabbitmq
================================

RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.

v15.0.1(1y ago)027MITPHPPHP ^8.1

Since Jan 28Pushed 1y agoCompare

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

READMEChangelog (2)Dependencies (8)Versions (95)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/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/vyuldashev/laravel-queue-rabbitmq/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/f38a16fd27cfaa1a90e2c6bca3d4b04a9e5d73abb89d388dabc6e4c86354c4bc/68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)[![License](https://camo.githubusercontent.com/5d5fd5b6ae3ea751391bfefbbb234e670205414b1ec2a8e06f789a9ee277ea6b/68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq)

⚠️ DISCONTINUED, [USE ORIGINAL REPO](https://github.com/vyuldashev/laravel-queue-rabbitmq) ⚠️
=============================================================================================

[](#️-discontinued-use-original-repo-️)

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.

### Configuration

[](#configuration)

Add connection to `config/queue.php`:

> This is the minimal config for the rabbitMQ connection/driver to work.

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

    'rabbitmq' => [

       'driver' => 'rabbitmq',
       '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', '/'),
           ],
           // ...
       ],

       // ...
    ],

    // ...
],
```

### Optional Queue Config

[](#optional-queue-config)

Optionally add queue options to the config of a connection. Every queue created for this connection, gets 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-keys, 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 an exchange with routing-key, you 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, you 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',
            ],
        ],
    ],

    // ...
],
```

### Horizon support

[](#horizon-support)

Starting with 8.0, this package supports [Laravel Horizon](https://laravel.com/docs/horizon) out of the box. Firstly, install Horizon and then set `RABBITMQ_WORKER` to `horizon`.

Horizon is depending on events dispatched by the worker. These events inform Horizon what was done with the message/job.

This Library supports Horizon, but in the config you have to inform Laravel to use the QueueApi compatible with horizon.

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

    'rabbitmq' => [
        // ...

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

    // ...
],
```

### 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 a `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:

```
