Download the PHP package ruima/microservice-tool without Composer
On this page you can find all versions of the php package ruima/microservice-tool. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ruima/microservice-tool
More information about ruima/microservice-tool
Files in ruima/microservice-tool
Package microservice-tool
Short Description Some public methods for ruima microservice framewoek.
License MIT
Informations about the package microservice-tool
Ruima Microserver Framework base on Lumen
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?
- 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
- PHP >= 7.1.3
- Lumen >= 5.8
- Guzzle >= 6.3
- illuminate/redis >= 5.8
- predis/predis >= 1.1
Installation via Composer
Or if you prefer, edit composer.json
manually:
Starting The Scheduler
You need to add the following Cron entry to your server.
Modify the service environment ( file)
For Microservice:
For Auth Microservice:
You need to add APP_KEY
For Gateway:
Modify the bootstrap flow ( file)
For Microservice:
For Gateway:
Installed routes
For Microservice:
Verb | Path | Controller | Action |
---|---|---|---|
GET | /health-check | \Ruima\MicroserviceTool\Controllers\SalverController | healthCheck |
GET | /heart-beat | \Ruima\MicroserviceTool\Controllers\SalverController | heartBeat |
For Gateway:
Verb | Path | Controller | Action |
---|---|---|---|
GET | /health-check | \Ruima\MicroserviceTool\Controllers\MasterController | healthCheck |
GET | /heart-beat-check | \Ruima\MicroserviceTool\Controllers\MasterController | heartBeatCheck |
GET | /registe-microserver | \Ruima\MicroserviceTool\Controllers\MasterController | healthCheck |
POST | /distroy-auth | \Ruima\MicroserviceTool\Controllers\MasterController | registerMicroserver |
DELETE | /health-check | \Ruima\MicroserviceTool\Controllers\MasterController | distroyAuthToken |
GET | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
POST | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
PUT | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
PATCH | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
DELETE | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
OPTIONS | {path:.*} | \Ruima\MicroserviceTool\Controllers\MasterController | distribute |
Installed schedules & commandsdules
For Microservice:
Cycle | Command | Description |
---|---|---|
5MIN | microserver:heart-beat | send the microservice info to gateway |
For Gateway:
Cycle | Command | Description |
---|---|---|
5MIN | microserver:heart-beat-check | check the info in gateway |
Installed methods
For Microservice:
For Gateway:
Destribute request to target microservice
Follow this rule:
.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.
Use Authorization In 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:
The suggest user auth info format:
In Other microservice
Use middleware auth in your route
In Route
In Controller
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.
All versions of microservice-tool with dependencies
guzzlehttp/guzzle Version ^6.3
illuminate/redis Version ^5.8
laravel/lumen-framework Version ^5.8
predis/predis Version ^1.1