2.1.0-beta.0 • Published 2 years ago
@rugo-vn/service v2.1.0-beta.0
Rugo Service
Base for microservice system - Unit to build Rugo Platform.
Concept
systemis an entire program, which run by node command.- The
systemis devided into units, calledservice. serviceidentity isname. It's a unique value.- Super
serviceto create, load and start other services, callcedbroker. - Services were created by same
broker, calledscope. - In
scope, every services share a same variable calledglobals. You can accessglobalsanywhere from the service throughthis.globals. - In
scope, every services can be execute functions from another service bycallmethod, which can access anywhere in the service throughthis.call. - In
service, you can bind functions tothis, these functions calledmethod. this.callwill call a function, calledaction. The call must have aaddressof theactionyou want to execute by format<name>.<action>.- You can bind functions before, after and when error occur by
hooks.
Service Structure
const serviceDefine = {
name: /* ... */,
settings: {
/* ... */
},
methods: {
async methodName(/* ... */) {
/* ... */
},
/* ... */
},
actions: {
async actionName(/* ... */) {
/* ... */
},
/* ... */
},
hooks: {
before: {
async all(/* ... */) {
/* ... */
},
/* ... */
},
after: {
async all(/* ... */) {
/* ... */
},
/* ... */
},
error: {
async all(/* ... */) {
/* ... */
},
/* ... */
}
},
async started(/* ... */) {
/* ... */
},
async closed(/* ... */) {
/* ... */
},
}Usage
const settings = {
_services: [
'/path/to/service',
/* ... */
],
_globals: {
/* global variables */
}
}
const broker = createBroker(settings);
const service = broker.createService(serviceDefine);
await broker.loadServices();
await broker.start();
await broker.close();License
MIT.
2.1.0-beta.5
2 years ago
2.1.0-beta.4
2 years ago
2.1.0-beta.1
3 years ago
2.1.0-beta.0
3 years ago
2.0.2
3 years ago
2.1.0-beta.3
3 years ago
2.1.0-beta.2
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
2.0.0-beta.2
3 years ago
2.0.0-beta.1
3 years ago
2.0.0-beta.0
3 years ago