@zcws/micro
v0.5.2
Published
zcw micro component.
Downloads
13
Readme
micro组件
- 本组件用于构建基于Node.js微服务,服务治理使用consul,RPC通讯使用HTTP,数据格式JSON-RPC 2.0。
如何安装
npm install @zcws/micro --save
如何使用
Server
const { Server } = require('@zcws/micro'); let server = new Server({ port:'8500', host:'172.16.1.3' }); //添加method server.method('add',function(args,done){ let [a,b] = args; done(null,a+b); }); //批量添加method server.methods({ add(args,done){ let [a,b] = args; done(null,a+b); } }); //服务注册 server.register({ name:'wx', port:3000, address:'http://wx' }); //express中间件 app.use(server.middleware({ health:ture }));
Client
const { Client } = require('@zcws/micro'); let client = new Client({ port:8500, host:'172.16.1.3', use:['auth','wx'] }); let result = await client.apply('wx','publish',{ openid... });