moleculer-nativecall
v0.0.1
Published
Wrap service [D[D[D[D[D[D[D[D[D[F[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[B[B[D[D[D[D[D[D[D[D[D[D[D[D[Cas native object[D[D[D[D[D[D[D [F[F[F[B[B[B
Downloads
1
Readme
Moleculer NativeCall
Use other services as native objects for MoleculerJS framework
Install
$ npm install nervmouse/moleculer-nativecall
Usage
The ordinary way to call an action of service math
//Ordinay way to call `math.add`
ctx.call('math.add',{a:5,b:3}).then(res=> console.log('5+3=',res));
//Use NativeCall to call `math.add`
math.add({a:5,b:3}).then(res=> console.log('5+3=',res));
Sample Service
const NativeCall=require('moleculer-nativecall');
module.exports = {
name: "sample",
// Actions
actions: {
test (ctx){
return math.add({a:5,b:3}).then(res=> `5+3=${res}`)
}
},
// use NativeCall.require function in event handler
started() {
return NativeCall.require(this.broker,['math'],global);
}
};
API
NativeCall
object
require()
require(broker: ServiceBroker, services: Array [, env: object])
Parameters
| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |
| broker
| ServiceBroker| - | broker for accessing services |
| services
| Array| - | List of services to be loaded |
| env
| Object| {} | (optional) The place to assign service objects. The object will be return in promise. eg. global |
| | |
Return
a promise will be return with env
NativeCall.require(broker,['math']).then($env=>{
//$env.math will be the service object
});