PHPackages                             mhsaheb/laravel-rpc-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. [API Development](/categories/api)
4. /
5. mhsaheb/laravel-rpc-rabbitmq

ActiveLibrary[API Development](/categories/api)

mhsaheb/laravel-rpc-rabbitmq
============================

Request/Reply (RPC) over RabbitMQ for Laravel, using direct-reply-to.

1.0.4(9mo ago)15MITPHPPHP &gt;=8.1

Since Aug 13Pushed 9mo agoCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (0)

Laravel RabbitMQ RPC (RabbitRPC)
================================

[](#laravel-rabbitmq-rpc-rabbitrpc)

A simple **Request/Reply (RPC)** layer for Laravel microservices over **RabbitMQ**, built on top of `php-amqplib`. It lets your Laravel services call each other **synchronously** (like a local function) without HTTP.

---

Features
--------

[](#features)

- 🐇 Works with **RabbitMQ** (supports direct-reply-to for low-latency RPC)
- ♻ Reuses your existing `queue.connections.rabbitmq` config (compatible with `vladimir-yuldashev/laravel-queue-rabbitmq`)
- ⏱ Built-in timeouts, retries, and circuit breaker
- 📦 Easy route registration (via config, routes file, or CLI)
- 🔍 Pass arbitrary payload arrays between services
- 🛡 Supports meta info for request tracing or auth

---

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

[](#installation)

### 1) Require the package

[](#1-require-the-package)

```
composer require mhsaheb/laravel-rpc-rabbitmq
```

---

### 2) Publish the config

[](#2-publish-the-config)

```
php artisan vendor:publish --provider="RabbitRPC\\RpcServiceProvider" --tag=config
```

This will create `config/rpc.php`.

---

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

[](#configuration)

Edit `.env` in each service:

```
# Map logical endpoints to queues
RPC_SERVICE1_QUEUE=service-1-queue
RPC_SERVICE2_QUEUE=service-2-queue

# Client defaults
RPC_TIMEOUT=3
RPC_RETRIES=0
RPC_RETRY_DELAY_MS=100

# Circuit breaker
RPC_CB_FAILS=5
RPC_CB_OPEN_SEC=15
```

And in `config/rpc.php` you can map endpoints and routes:

```
return [
    'endpoints' => [
        'service-1'        => env('RPC_SERVICE1_QUEUE', 'service-1-queue'),
        'service-2' => env('RPC_SERVICE2_QUEUE', 'service-2-queue'),
    ],

    'timeout_seconds' => (float) env('RPC_TIMEOUT', 3.0),
    'retries'         => (int) env('RPC_RETRIES', 0),
    'retry_delay_ms'  => (int) env('RPC_RETRY_DELAY_MS', 100),

    'cb' => [
        'failure_threshold' => (int) env('RPC_CB_FAILS', 5),
        'open_seconds'      => (int) env('RPC_CB_OPEN_SEC', 15),
    ],

    'routes' => [
        'service-1' => [
           // 'service-1.create'     => 'MyService@create',
           // 'service-1.getProfile' => 'MyService@getProfile',
        ],
        'service-2' => [
            //'service-2.submit'   =>'MyService@submit',
        ],
    ],
];
```

---

Defining RPC Routes
-------------------

[](#defining-rpc-routes)

### Option 1 — Config map

[](#option-1--config-map)

Add to `config/rpc.php` under `'routes'`.

### Option 2 — Per-endpoint routes file

[](#option-2--per-endpoint-routes-file)

Create `routes/rpc_user.php`:

```
use App\\Services\\UserService;

return [
    'user.create' => UserService::class.'@create',
    'user.getProfile' => UserService::class.'@getProfile',
];
```

### Option 3 — CLI flag

[](#option-3--cli-flag)

```
php artisan rpc:consume user --route="user.create=App\\Services\\UserService@create"
```

---

Running the Responder
---------------------

[](#running-the-responder)

A **responder** listens on a queue for requests and returns a reply.

Example: In `user_service`, to expose `user.create`:

```
php artisan rpc:consume user
```

This will load all routes for `user` from config or `routes/rpc_user.php`.

Your handler method:

```
namespace App\\Services;

class UserService
{
    public function create(array $params): array
    {
        // $params = ['name' => ..., 'email' => ...]
        $user = User::create([
            'name' => $params['name'],
            'email' => $params['email'],
            'phone' => $params['phone'] ?? null,
            'password' => bcrypt('secret'),
        ]);

        return $user->toArray();
    }
}
```

---

Calling Another Service
-----------------------

[](#calling-another-service)

From **accelerator\_service**, call `user.create` on the `user_service`:

```
use RabbitRPC\\Facades\\Rpc; // or DI via RabbitRPC\\Contracts\\Client

Route::post('/provision-user', function (Request $request) {
    $payload = $request->only('name', 'email', 'phone');
    $user = Rpc::call('user', 'user.create', $payload);

    return response()->json([
        'created' => true,
        'user' => $user,
    ]);
});
```

---

Payload &amp; Meta
------------------

[](#payload--meta)

The `call()` method signature:

```
Rpc::call(string $endpoint, string $route, array $payload = [], ?float $timeoutSeconds = null): array
```

- `$endpoint` — logical key from `config/rpc.php` (`user`, `accelerator`, etc.)
- `$route` — route string that matches the responder’s handler
- `$payload` — associative array of data to pass
- `$timeoutSeconds` — optional per-call override

The responder receives:

```
function (array $payload, array $meta) { ... }
```

`$meta` contains info like `request_id`, `app`, `ts`.

---

Health Check
------------

[](#health-check)

Every responder auto-registers a `ping` route:

```
php artisan tinker
>>> Rpc::call('user', 'ping');
# ['ok' => true, 'endpoint' => 'user', 'at' => '2025-08-13T11:00:00Z']
```

---

Supervising
-----------

[](#supervising)

In production, run responders under Supervisor or systemd:

**supervisor.conf**

```
[program:rpc-user]
command=php artisan rpc:consume user
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/rpc-user.log

```

---

Advanced
--------

[](#advanced)

- **Per-route timeouts/retries:** Extend `RpcClient` to look up route-specific settings.
- **Idempotency:** Store `meta.request_id` on side-effecting routes to avoid duplicates.
- **Security:** Check `$meta` for a service token in each handler.

---

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance58

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

2

Last Release

272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6a54149596771c681b8fc3952aaf7bcfa768d443028bee8d8f4d387054431a?d=identicon)[MHSahebgharani](/maintainers/MHSahebgharani)

### Embed Badge

![Health badge](/badges/mhsaheb-laravel-rpc-rabbitmq/health.svg)

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

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23414.2M16](/packages/hubspot-api-client)

PHPackages © 2026

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