PHPackages                             kuncen/mcs-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. kuncen/mcs-laravel-rabbitmq

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

kuncen/mcs-laravel-rabbitmq
===========================

RabbitMQ Publisher and Consumer Laravel for Microservices Architecture

v1.1.0(1w ago)023↓100%MITPHPPHP ^8.1

Since Mar 3Pushed 1w agoCompare

[ Source](https://github.com/MFadlulHafiizh/laravel-rabbitmq-microservice)[ Packagist](https://packagist.org/packages/kuncen/mcs-laravel-rabbitmq)[ RSS](/packages/kuncen-mcs-laravel-rabbitmq/feed)WikiDiscussions main Synced today

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

MCS Laravel RabbitMQ
====================

[](#mcs-laravel-rabbitmq)

RabbitMQ Publisher &amp; Consumer for Laravel Microservices Architecture.

Supports:

- Lazy connection (safe for package boot)
- Topic / Direct exchange publishing
- Queue-based consumer
- Artisan listener generator
- Production-ready worker with Supervisor

---

🇺🇸 English Documentation
========================

[](#-english-documentation)

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

[](#installation)

```
composer require kuncen/mcs-laravel-rabbitmq
```

---

Publish Configuration
---------------------

[](#publish-configuration)

```
php artisan vendor:publish --provider="Kuncen\McsRabbitMQ\RabbitMQServiceProvider"
```

This will publish:

```
config/rabbitmq.php

```

---

Environment Configuration
-------------------------

[](#environment-configuration)

Add to `.env`:

```
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
RABBITMQ_EXCHANGE=
```

---

Publishing Messages
===================

[](#publishing-messages)

Inject Publisher
----------------

[](#inject-publisher)

```
use Kuncen\MCSLaravel\RabbitMQ\Services\RabbitMQPublisher;

class UserController extends Controller
{
    public function store(RabbitMQPublisher $publisher)
    {
        $publisher->publish(
            payload: [
                'user_id' => 1,
                'name' => 'John Doe'
            ],
            routingKey: 'user.created'
        );

        return response()->json(['status' => 'Message sent']);
    }
}
```

---

Publisher Method Signature
--------------------------

[](#publisher-method-signature)

```
publish(
    array $payload,
    string $routingKey,
    string $exchangeType = 'topic',
    ?string $exchange = null
)
```

---

Listening (Consumer)
====================

[](#listening-consumer)

Create Listener
---------------

[](#create-listener)

```
php artisan make:rabbitlistener UserCreatedListener
```

Generated example:

```
class UserCreatedListener implements RabbitMQListener
{
    public static function queue(): string
    {
        return 'user.created';
    }

    public function handle(array $payload): void
    {
        // Your business logic here
    }
}
```

---

Run Worker
----------

[](#run-worker)

```
php artisan rabbitmq:consume UserCreatedListener
```

Worker will listen to:

```
user.created

```

---

Production Setup (Supervisor)
=============================

[](#production-setup-supervisor)

Create file:

```
/etc/supervisor/conf.d/rabbitmq-user-created.conf

```

Content:

```
[program:rabbitmq-user-created]
process_name=%(program_name)s_%(process_num)02d
command=php /path-to-project/artisan rabbitmq:consume UserCreatedListener
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/path-to-project/storage/logs/rabbitmq-user-created.log
stopwaitsecs=3600
```

Reload Supervisor:

```
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start rabbitmq-user-created
```

---

Best Practices
==============

[](#best-practices)

- Do not auto-declare exchange in production.
- Let infrastructure manage queue arguments.
- Use Supervisor for production workers.
- Recommended: 1 queue = 1 listener.

---

🇮🇩 Dokumentasi Bahasa Indonesia
===============================

[](#-dokumentasi-bahasa-indonesia)

Instalasi
---------

[](#instalasi)

```
composer require kuncen/mcs-laravel-rabbitmq
```

---

Publish Konfigurasi
-------------------

[](#publish-konfigurasi)

```
php artisan vendor:publish --provider="Kuncen\McsRabbitMQ\RabbitMQServiceProvider"
```

File yang akan dibuat:

```
config/rabbitmq.php

```

---

Konfigurasi .env
----------------

[](#konfigurasi-env)

Tambahkan:

```
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
RABBITMQ_EXCHANGE=
```

---

Mengirim Pesan (Publish)
========================

[](#mengirim-pesan-publish)

Inject Publisher ke Controller
------------------------------

[](#inject-publisher-ke-controller)

```
use Kuncen\MCSLaravel\RabbitMQ\Services\RabbitMQPublisher;

class UserController extends Controller
{
    public function store(RabbitMQPublisher $publisher)
    {
        $publisher->publish(
            payload: [
                'user_id' => 1,
                'name' => 'John Doe'
            ],
            routingKey: 'user.created'
        );

        return response()->json(['status' => 'Message sent']);
    }
}
```

---

Signature Method
----------------

[](#signature-method)

```
publish(
    array $payload,
    string $routingKey,
    string $exchangeType = 'topic',
    ?string $exchange = null
)
```

---

Listening / Consumer
====================

[](#listening--consumer)

Membuat Listener
----------------

[](#membuat-listener)

```
php artisan make:rabbitlistener UserCreatedListener
```

Contoh isi listener:

```
class UserCreatedListener implements RabbitMQListener
{
    public static function queue(): string
    {
        return 'user.created';
    }

    public function handle(array $payload): void
    {
        // Logic bisnis di sini
    }
}
```

---

Menjalankan Worker
------------------

[](#menjalankan-worker)

```
php artisan rabbitmq:consume UserCreatedListener
```

Worker akan listen ke queue:

```
user.created

```

---

Setup Production (Supervisor)
=============================

[](#setup-production-supervisor)

Buat file:

```
/etc/supervisor/conf.d/rabbitmq-user-created.conf

```

Isi:

```
[program:rabbitmq-user-created]
process_name=%(program_name)s_%(process_num)02d
command=php /path-to-project/artisan rabbitmq:consume UserCreatedListener
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/path-to-project/storage/logs/rabbitmq-user-created.log
stopwaitsecs=3600
```

Reload supervisor:

```
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start rabbitmq-user-created
```

---

Rekomendasi
===========

[](#rekomendasi)

- Hindari auto declare exchange di production.
- Biarkan konfigurasi queue dikelola oleh infrastructure.
- Gunakan Supervisor untuk worker.
- Disarankan 1 queue = 1 listener untuk arsitektur microservice.

---

License
=======

[](#license)

MIT

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance98

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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 ~1 days

Total

7

Last Release

9d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b99f20e76c246f5275587a52bfd5775ac4a9ded3fb4efe7c0e4ffc9c390a4ee?d=identicon)[rrkuncen](/maintainers/rrkuncen)

---

Top Contributors

[![MFadlulHafiizh](https://avatars.githubusercontent.com/u/61264072?v=4)](https://github.com/MFadlulHafiizh "MFadlulHafiizh (1 commits)")

---

Tags

laravelrabbitmqMicroservice

### Embed Badge

![Health badge](/badges/kuncen-mcs-laravel-rabbitmq/health.svg)

```
[![Health](https://phpackages.com/badges/kuncen-mcs-laravel-rabbitmq/health.svg)](https://phpackages.com/packages/kuncen-mcs-laravel-rabbitmq)
```

###  Alternatives

[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[mookofe/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

5552.3k](/packages/mookofe-tail)[kunalvarma05/laravel-rabbitmq

Work with RabbitMQ in Laravel.

1851.0k](/packages/kunalvarma05-laravel-rabbitmq)[kontoulis/rabbitmq-laravel

RabbitMQ Broker for Laravel

161.2k](/packages/kontoulis-rabbitmq-laravel)

PHPackages © 2026

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