PHPackages                             aachich/message-broker - 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. aachich/message-broker

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

aachich/message-broker
======================

AMQP Message Broker abstraction for Laravel - easily switch between RabbitMQ and other AMQP-compatible brokers

v1.0.0(3mo ago)10MITPHPPHP ^8.1

Since Feb 8Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/rachid-aachich/laravel-amqp-broker)[ Packagist](https://packagist.org/packages/aachich/message-broker)[ Docs](https://github.com/rachid-aachich/laravel-amqp-broker)[ RSS](/packages/aachich-message-broker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Laravel AMQP Message Broker
===========================

[](#laravel-amqp-message-broker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/30906a6f0da46f833ea1521a52980b7d38f816abbc13b1b7b65c93a28a54e756/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616163686963682f6d6573736167652d62726f6b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aachich/message-broker)[![PHP Version](https://camo.githubusercontent.com/72b5695fc34b379ccb80f05c557f88c94f55c9854c9ebc4ec75e571d5757b6e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616163686963682f6d6573736167652d62726f6b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aachich/message-broker)[![License](https://camo.githubusercontent.com/eb7e9d4c832047ab915d3d17a70436661aa58ac00cdafcb43b84c74e70106e95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616163686963682f6d6573736167652d62726f6b65722e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A Laravel package providing an abstraction layer for AMQP message brokers. Easily switch between RabbitMQ and other AMQP-compatible brokers without changing your application code.

Features
--------

[](#features)

- 🔄 **Broker Abstraction** - Switch message brokers without code changes
- ⚡ **Fiber-based Async** - Non-blocking publish/consume using PHP 8.1+ Fibers
- 🔁 **Automatic Retries** - Configurable connection retry with exponential backoff
- 📦 **Bulk Publishing** - Efficiently publish collections of messages
- 💀 **Dead Letter Queue** - Automatic DLQ routing for failed messages
- 🎯 **Exchange Support** - Publish to queues or exchanges with routing keys

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.x or 11.x
- RabbitMQ (or any AMQP-compatible broker)

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

[](#installation)

```
composer require aachich/message-broker
```

The package will auto-register its service provider.

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --provider="Aachich\MessageBroker\MessageBrokerServiceProvider" --tag=config
```

### Environment Variables

[](#environment-variables)

Add these to your `.env` file:

```
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
RABBITMQ_QUEUE_CONSUMER=my-consume-queue
RABBITMQ_QUEUE_PUBLISHER=my-publish-queue
RABBITMQ_QUEUE_REJECT=my-dlq
RABBITMQ_MAX_RETRIES=30
```

Usage
-----

[](#usage)

### Basic Publishing

[](#basic-publishing)

```
use Aachich\MessageBroker\Facades\MessageBroker;

// Connect first
MessageBroker::connect();

// Publish a message
MessageBroker::publishToQueue($message, 'my-queue', ['header-key' => 'value']);

// Publish to an exchange
MessageBroker::publishToExchange($message, 'my-exchange', [], 'routing.key');
```

### Consuming Messages

[](#consuming-messages)

```
use Aachich\MessageBroker\Facades\MessageBroker;

MessageBroker::connect();

MessageBroker::consumeMessage('my-queue', function ($message) {
    // Process the message
    $body = $message->getBody();

    // Return true to acknowledge, false to reject
    return true;
});
```

### Bulk Publishing

[](#bulk-publishing)

```
use Illuminate\Support\Collection;

$messages = collect(['msg1', 'msg2', 'msg3']);

MessageBroker::publishBulkMessagesToQueue($messages, 'my-queue');
```

### Check Connection Status

[](#check-connection-status)

```
$status = MessageBroker::getStatus();
// Returns: ['brokerName' => 'RabbitMQ', 'connect' => true, 'consuming' => false]
```

Extending with Custom Brokers
-----------------------------

[](#extending-with-custom-brokers)

To add support for a new AMQP broker:

1. Create a repository implementing `BrokerRepoInterface`:

```
use Aachich\MessageBroker\Contracts\BrokerRepoInterface;

class MyCustomBrokerRepository implements BrokerRepoInterface
{
    // Implement all interface methods
}
```

2. Update the service provider binding based on config:

```
$this->app->singleton(BrokerRepoInterface::class, function ($app) {
    return match(config('messagebroker.default')) {
        'rabbitmq' => new RabbitMQRepository(),
        'custom' => new MyCustomBrokerRepository(),
        default => throw new InvalidMessageBrokerNameException(),
    };
});
```

Testing
-------

[](#testing)

```
vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please submit a PR against the `main` branch.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance82

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.3% 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

Unknown

Total

1

Last Release

97d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb06b0ad80cb68352f436f6cae7f89143000dc78b9e9e22288b8ec8c7f992328?d=identicon)[rachid-aachich](/maintainers/rachid-aachich)

---

Top Contributors

[![terabytesw](https://avatars.githubusercontent.com/u/64411365?v=4)](https://github.com/terabytesw "terabytesw (23 commits)")[![rachid-aachich](https://avatars.githubusercontent.com/u/28694723?v=4)](https://github.com/rachid-aachich "rachid-aachich (4 commits)")[![abdearec](https://avatars.githubusercontent.com/u/34132990?v=4)](https://github.com/abdearec "abdearec (2 commits)")

---

Tags

phplaravelqueuerabbitmqmessagingAMQPmessage-broker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aachich-message-broker/health.svg)

```
[![Health](https://phpackages.com/badges/aachich-message-broker/health.svg)](https://phpackages.com/packages/aachich-message-broker)
```

###  Alternatives

[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[nuwber/rabbitevents

The Nuwber RabbitEvents package

120515.8k3](/packages/nuwber-rabbitevents)[iamfarhad/laravel-rabbitmq

A robust RabbitMQ driver for Laravel Queue with advanced message queuing, reliable delivery, and high-performance async processing capabilities

3215.6k](/packages/iamfarhad-laravel-rabbitmq)[kdyby/rabbitmq

Integrates php-amqplib with RabbitMq and Nette Framework

30693.1k4](/packages/kdyby-rabbitmq)

PHPackages © 2026

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