PHPackages                             maestrodimateo/simple-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. maestrodimateo/simple-rabbitmq

ActiveLibrary

maestrodimateo/simple-rabbitmq
==============================

A simple, dev-friendly Laravel wrapper for RabbitMQ

v1.1.4(1mo ago)213↑592.3%MITPHPPHP ^8.3 || ^8.4

Since Apr 5Pushed 1w agoCompare

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

READMEChangelogDependencies (6)Versions (7)Used By (0)

Simple RabbitMQ
===============

[](#simple-rabbitmq)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4e5819a70d187b86f28eabbfde8ac0e3245625f35676b35887a7497a0648b973/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61657374726f64696d6174656f2f73696d706c652d7261626269746d712e737667)](https://packagist.org/packages/maestrodimateo/simple-rabbitmq)[![License](https://camo.githubusercontent.com/9950fe720bb1242637b1a328f391e681b54758cedc618562d794307b6295aaad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61657374726f64696d6174656f2f73696d706c652d7261626269746d712e737667)](https://packagist.org/packages/maestrodimateo/simple-rabbitmq)

A simple, dev-friendly Laravel wrapper for [RabbitMQ](https://www.rabbitmq.com/).

Built on top of [php-amqplib](https://github.com/php-amqplib/php-amqplib), this package provides a clean Facade for publishing and consuming messages — with auto JSON, typed message objects, dead-letter queues, and retry out of the box.

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

[](#installation)

```
composer require maestrodimateo/simple-rabbitmq
```

Publish the config:

```
php artisan vendor:publish --tag=rabbitmq-config
```

Add to your `.env`:

```
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
```

---

Quick Start
-----------

[](#quick-start)

### Publish a message

[](#publish-a-message)

```
use Maestrodimateo\SimpleRabbitMQ\Facades\RabbitMQ;

// Simple publish
RabbitMQ::publish('orders.created', ['order_id' => 123, 'total' => 99.99]);

// Publish to a specific exchange
RabbitMQ::to('billing.events')->publish('invoice.paid', $data);

// Via a typed Message Object
RabbitMQ::send(new OrdreAchatMessage($ordre));
```

### Consume messages

[](#consume-messages)

Define listeners in `routes/rabbitmq.php` (create this file):

```
use Maestrodimateo\SimpleRabbitMQ\Facades\RabbitMQ;
use App\RabbitMQ\Handlers\ProcessOrderHandler;
use App\RabbitMQ\Handlers\ProcessPaymentHandler;

RabbitMQ::listen('orders.created', ProcessOrderHandler::class);
RabbitMQ::listen('payments.*', ProcessPaymentHandler::class);
```

Start the consumer:

```
php artisan rabbitmq:consume
```

---

Message Objects
---------------

[](#message-objects)

Generate a typed message:

```
php artisan make:rabbitmq-message OrdreAchatMessage
```

This creates `app/RabbitMQ/Messages/OrdreAchatMessage.php`:

```
use Maestrodimateo\SimpleRabbitMQ\Messages\RabbitMQMessage;

class OrdreAchatMessage extends RabbitMQMessage
{
    public string $routingKey = 'ordre.achat';

    public function __construct(public readonly Ordre $ordre) {}

    public function payload(): array
    {
        return [
            'ticker' => $this->ordre->ticker,
            'prix' => $this->ordre->prix,
        ];
    }
}
```

Publish it:

```
RabbitMQ::send(new OrdreAchatMessage($ordre));
```

---

Message Handlers
----------------

[](#message-handlers)

Generate a handler:

```
php artisan make:rabbitmq-handler ProcessOrderHandler
```

This creates `app/RabbitMQ/Handlers/ProcessOrderHandler.php`:

```
use Maestrodimateo\SimpleRabbitMQ\Contracts\MessageHandler;
use Maestrodimateo\SimpleRabbitMQ\Messages\IncomingMessage;

class ProcessOrderHandler extends MessageHandler
{
    public function handle(IncomingMessage $message): void
    {
        $data = $message->payload();       // Decoded array
        $key  = $message->routingKey();    // 'orders.created'
        $raw  = $message->raw();           // Raw JSON string

        // Your processing logic here
        // No need to ack — handled automatically
        // Throw an exception to trigger retry/DLQ
    }
}
```

### IncomingMessage API

[](#incomingmessage-api)

MethodReturnsDescription`payload()``array`Decoded JSON payload`get($key, $default)``mixed`Get a specific payload value`routingKey()``string`The routing key`exchange()``string`The exchange name`raw()``string`Raw JSON body`header($key)``mixed`Get a specific header`headers()``array`All headers`retryCount()``int`Number of retry attempts---

Simple Callback Consumer
------------------------

[](#simple-callback-consumer)

For quick one-off consumers without a handler class:

```
RabbitMQ::consume('orders.created', function (array $data) {
    // Process the order
    Order::create($data);
});
```

---

Dead Letter Queue
-----------------

[](#dead-letter-queue)

Failed messages are automatically routed to a dead-letter queue after max retries. Enabled by default.

```
RABBITMQ_DLX_ENABLED=true
RABBITMQ_DLX_EXCHANGE=dlx
```

Each queue gets a corresponding `.dlq` queue (e.g., `orders.created` → `orders.created.dlq`).

---

Retry
-----

[](#retry)

Messages that throw an exception are retried automatically:

```
RABBITMQ_RETRY_ENABLED=true
RABBITMQ_RETRY_MAX=3
RABBITMQ_RETRY_DELAY=5000
```

After `max_attempts`, the message goes to the DLQ.

---

Exchanges
---------

[](#exchanges)

The default exchange is `app` with type `topic`. Configure in `.env`:

```
RABBITMQ_EXCHANGE=my-exchange
RABBITMQ_EXCHANGE_TYPE=topic
```

### Exchange types

[](#exchange-types)

All four AMQP exchange types are supported with fluent shortcuts:

```
// Topic (default) — routing key with wildcards (*, #)
RabbitMQ::publish('orders.created', $data);
RabbitMQ::topic('events')->publish('user.login', $data);

// Direct — exact routing key match
RabbitMQ::direct('tasks')->publish('send-email', $data);

// Fanout — broadcast to all bound queues (routing key ignored)
RabbitMQ::fanout('notifications')->publish('', $data);

// Headers — routed by AMQP headers
RabbitMQ::headers('matching')->publish('', $data, ['x-match' => 'all', 'type' => 'urgent']);
```

You can also use `to()` with an explicit type:

```
RabbitMQ::to('my-exchange', 'direct')->publish('key', $data);
```

Each exchange is declared independently with its own type. You can mix different exchange types in the same application.

---

Configuration
-------------

[](#configuration)

```
// config/rabbitmq.php
return [
    'host'     => env('RABBITMQ_HOST', '127.0.0.1'),
    'port'     => (int) env('RABBITMQ_PORT', 5672),
    'user'     => env('RABBITMQ_USER', 'guest'),
    'password' => env('RABBITMQ_PASSWORD', 'guest'),
    'vhost'    => env('RABBITMQ_VHOST', '/'),

    'exchange' => [
        'name'    => env('RABBITMQ_EXCHANGE', 'app'),
        'type'    => env('RABBITMQ_EXCHANGE_TYPE', 'topic'),
        'durable' => true,
    ],

    'queue' => [
        'durable'     => true,
        'auto_delete' => false,
        'exclusive'   => false,
    ],

    'consumer' => [
        'prefetch_count' => (int) env('RABBITMQ_PREFETCH', 1),
    ],

    'dead_letter' => [
        'enabled'      => true,
        'exchange'     => 'dlx',
        'queue_suffix' => '.dlq',
    ],

    'retry' => [
        'enabled'      => true,
        'max_attempts' => 3,
        'delay_ms'     => 5000,
    ],
];
```

---

Artisan Commands
----------------

[](#artisan-commands)

CommandDescription`rabbitmq:consume`Start consuming all registered listeners`make:rabbitmq-handler`Generate a new message handler class`make:rabbitmq-message`Generate a new typed message class---

Helper
------

[](#helper)

```
rabbitmq()->publish('key', $data);
rabbitmq()->to('exchange')->publish('key', $data);
```

---

Testing
-------

[](#testing)

```
./vendor/bin/pest tests/Unit
```

---

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

- [Noel Mebale](https://github.com/maestrodimateo)
- Built on [php-amqplib/php-amqplib](https://github.com/php-amqplib/php-amqplib)

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance96

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

33d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92a2c64304e341345f2854b5bc9c43806b9e54f0b5b9b57135d37d69dd7c5c67?d=identicon)[mebalenoel](/maintainers/mebalenoel)

---

Top Contributors

[![maestrodimateo](https://avatars.githubusercontent.com/u/40523415?v=4)](https://github.com/maestrodimateo "maestrodimateo (9 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/maestrodimateo-simple-rabbitmq/health.svg)

```
[![Health](https://phpackages.com/badges/maestrodimateo-simple-rabbitmq/health.svg)](https://phpackages.com/packages/maestrodimateo-simple-rabbitmq)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M686](/packages/barryvdh-laravel-ide-helper)[laravel/jetstream

Tailwind scaffolding for the Laravel framework.

4.1k19.8M136](/packages/laravel-jetstream)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
