PHPackages                             ruima/microservice-tool - 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. [Framework](/categories/framework)
4. /
5. ruima/microservice-tool

ActiveLibrary[Framework](/categories/framework)

ruima/microservice-tool
=======================

Some public methods for ruima microservice framewoek.

v0.1.1(6y ago)145MITPHPPHP &gt;=7.1.3

Since Jun 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Leungsiuyin/ruima-microservice-tool)[ Packagist](https://packagist.org/packages/ruima/microservice-tool)[ RSS](/packages/ruima-microservice-tool/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (4)Versions (7)Used By (0)

Ruima Microserver Framework base on Lumen
=========================================

[](#ruima-microserver-framework-base-on-lumen)

Description
-----------

[](#description)

This is a microserver framework that make it easy to build a microserver API server. The gateway will cache the user auth info (base info, roles info, premissions info) in redis.

What did this package do?
-------------------------

[](#what-did-this-package-do)

- Automatically distribute the requset to target microservice
- Use redis to cache the user auth info in gateway
- Authentication in gateway
- Api permission guard in microservice middleware

Dependencies
------------

[](#dependencies)

- PHP &gt;= 7.1.3
- Lumen &gt;= 5.8
- Guzzle &gt;= 6.3
- illuminate/redis &gt;= 5.8
- predis/predis &gt;= 1.1

Installation via Composer
-------------------------

[](#installation-via-composer)

```
$ composer require ruima/microservice-tool
```

Or if you prefer, edit `composer.json` manually:

```
{
    "require": {
        "ruima/microservice-tool": "^0.1.1"
    }
}
```

### Starting The Scheduler

[](#starting-the-scheduler)

You need to add the following Cron entry to your server.

```
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

```

### Modify the service environment (`.env` file)

[](#modify-the-service-environment-env-file)

#### For Microservice:

[](#for-microservice)

```
# (Require) the url of this service
APP_URL=http://your.app.url

# (Require) the url of gateway
MICROSERVICE_GATEWAY_URL = http://your.gateway.url

# (Require) the name of this microservice
MICROSERVICE_NAME = micro-data

# (Require) the type of this microservice
# auth (basic microservice) | data (normal microservice)
MICROSERVICE_TYPE = data

# (Not Require) the description of this microservice
MICROSERVICE_DESCRIPTION = 'Data microservice Demo'

# (Not Require) the version of this microservice, default return lumen's version
MICROSERVICE_VERSION = ''

# (Not Require) the administrator's code when using permission middleware (the administrator can access all controller), default ADMIN
MICROSERVICE_ADMIN_CODE = ADMIN

```

#### For Auth Microservice:

[](#for-auth-microservice)

You need to add APP\_KEY

```
APP_KEY=The only supported ciphers are AES-128-CBC or AES-256-CBC

```

#### For Gateway:

[](#for-gateway)

```
# The gateway use redis to cache the user auth info , you need to set the redis config
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password

# (Not Require) custom the microservices config list dir
MICROSERVICE_CONFIG_DIR = /absolute/path/to/your/config/dir

# (Not Require) print how much time spend when gateway distribute request.
MICROSERVICE_GATEWAY_TIME_LOG = true

```

### Modify the bootstrap flow (`bootstrap/app.php` file)

[](#modify-the-bootstrap-flow-bootstrapappphp-file)

#### For Microservice:

[](#for-microservice-1)

```
$app->singleton(
    'MicroserviceTool', function ($app) {
        return new Ruima\MicroserviceTool\Slaver($app);
    }
);

$app->routeMiddleware([
    'auth' => Ruima\MicroserviceTool\Middleware\FackAuth::class,
    'permission' => Ruima\MicroserviceTool\Middleware\Permission::class,
]);

$app->register(Ruima\MicroserviceTool\Provider\SlaverProvider::class);
```

#### For Gateway:

[](#for-gateway-1)

```
$app->register(Illuminate\Redis\RedisServiceProvider::class);

$app->register(Ruima\MicroserviceTool\Provider\MasterProvider::class);
```

### Installed routes

[](#installed-routes)

#### For Microservice:

[](#for-microservice-2)

VerbPathControllerActionGET/health-check\\Ruima\\MicroserviceTool\\Controllers\\SalverControllerhealthCheckGET/heart-beat\\Ruima\\MicroserviceTool\\Controllers\\SalverControllerheartBeat#### For Gateway:

[](#for-gateway-2)

VerbPathControllerActionGET/health-check\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerhealthCheckGET/heart-beat-check\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerheartBeatCheckGET/registe-microserver\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerhealthCheckPOST/distroy-auth\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerregisterMicroserverDELETE/health-check\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistroyAuthTokenGET{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistributePOST{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistributePUT{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistributePATCH{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistributeDELETE{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistributeOPTIONS{path:.\*}\\Ruima\\MicroserviceTool\\Controllers\\MasterControllerdistribute### Installed schedules &amp; commandsdules

[](#installed-schedules--commandsdules)

#### For Microservice:

[](#for-microservice-3)

CycleCommandDescription5MINmicroserver:heart-beatsend the microservice info to gateway#### For Gateway:

[](#for-gateway-3)

CycleCommandDescription5MINmicroserver:heart-beat-checkcheck the info in gateway### Installed methods

[](#installed-methods)

#### For Microservice:

[](#for-microservice-4)

```
#use app('MicroserviceTool') to get the MicroserviceTool Object
app('MicroserviceTool')->{methods};

# return an Array for microservice infos
getSlaverInfo()

# send the request to tell gateway destory the user cache in gateway
destoryAuth()

# return a String for target microservice url
getServerUrl(String $service_name)

# return a http body which the target microserver callback
get(String $service_name, String $url = '/the/route/which/defind/in/web.php/or/api.php', Array $guzzle_config = [])
post(String $service_name, String $url, Array $guzzle_config)
delete(String $service_name, String $url, Array $guzzle_config)
put(String $service_name, String $url, Array $guzzle_config)
```

#### For Gateway:

[](#for-gateway-4)

```
 (Comming soon)

```

### Destribute request to target microservice

[](#destribute-request-to-target-microservice)

Follow this rule:

```
http://gateway.url/microservice.name/microservice.router.url

```

.e.g There is a microservice which the `MICROSERVICE_NAME` in `.env` is "micro-auth", and it have a route `GET/auth-info`.When send a request use the following url, gateway will handle this automatically.

```
http://loacal.gateway.com/micro-auth/auth-info

```

### Use Authorization In Microservice

[](#use-authorization-in-microservice)

#### In Auth microservice

[](#in-auth-microservice)

You need to add a route "GET/auth-info", return a json format user auth info. when other microservice need the auth info, gate way will seed a http request with token in GET method to "/auth-info", then the gateway wiil use the last 64 bits of the token as the key to cache the response in redis. When auth info changed, you need to send a request "POST/distroy-auth" with body { short\_token (the last 64 bits of the token) } to gateway. if short\_token = "all", the gateway will clear all cache.

In api router:

```
$router->get('auth-info', 'AuthenticateController@getAuthInfo');
```

The suggest user auth info format:

```
{
    "id": 1,
    "name": "admin",
    "username": "admin",
    "token": "9hkIE4iVo_60QbbB8t1Ho-jkde7gzLZDubcUifRrd4YINZJxnq9F3-c6nJFS6EAk",
    "roles": [
      "admin",
    ],
    "permissons": [
      "ADMIN",
    ]
}
```

#### In Other microservice

[](#in-other-microservice)

##### Use middleware auth in your route

[](#use-middleware-auth-in-your-route)

In Route

```
$router->get('/', [ 'middleware' => 'auth' , function () use ($router) {
    return $router->app->version();
}]);
```

In Controller

```
public function index (Request $request) {
    $AUTH = $request->auth;
}
```

##### Use middleware permission in your route

[](#use-middleware-permission-in-your-route)

When using permission middle, it will use auth middleware automatically. and check the `\Array $request->auth['permissions']` have the right permissin or not. In the case of multiple permissions, as long as user have one permission, it will pass the permission check.

```
$router->get('/', [ 'middleware' => 'permission:PA ADMIN RE' , function () use ($router) {
    return $router->app->version();
}]);
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

2535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b145a4a70797bf1f52333ad8285d528a66ae09db31e8912da0e4e4ef50c28c59?d=identicon)[Leungsiuyin](/maintainers/Leungsiuyin)

---

Top Contributors

[![Leungsiuyin](https://avatars.githubusercontent.com/u/28927763?v=4)](https://github.com/Leungsiuyin "Leungsiuyin (21 commits)")

---

Tags

gateway-apilaravellumenmicroservice-frameworkphp

### Embed Badge

![Health badge](/badges/ruima-microservice-tool/health.svg)

```
[![Health](https://phpackages.com/badges/ruima-microservice-tool/health.svg)](https://phpackages.com/packages/ruima-microservice-tool)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

9.4k1.8k](/packages/unopim-unopim)[themosis/framework

The Themosis framework.

676307.9k18](/packages/themosis-framework)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[lion/bundle

Lion-framework configuration and initialization package

122.2k1](/packages/lion-bundle)

PHPackages © 2026

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