2.1.0-beta.0 • Published 11 months ago
@rugo-vn/service v2.1.0-beta.0
Rugo Service
Base for microservice system - Unit to build Rugo Platform.
Concept
system
is an entire program, which run by node command.- The
system
is devided into units, calledservice
. service
identity isname
. It's a unique value.- Super
service
to 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 accessglobals
anywhere from the service throughthis.globals
. - In
scope
, every services can be execute functions from another service bycall
method, which can access anywhere in the service throughthis.call
. - In
service
, you can bind functions tothis
, these functions calledmethod
. this.call
will call a function, calledaction
. The call must have aaddress
of theaction
you 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
11 months ago
2.1.0-beta.4
11 months ago
2.1.0-beta.1
1 year ago
2.1.0-beta.0
1 year ago
2.0.2
1 year ago
2.1.0-beta.3
1 year ago
2.1.0-beta.2
1 year ago
2.0.1
1 year ago
2.0.0
2 years ago
2.0.0-beta.2
2 years ago
2.0.0-beta.1
2 years ago
2.0.0-beta.0
2 years ago