egg-consul-pro
v0.0.1
Published
consul plugin for egg
Downloads
2
Readme
egg-consul-pro
consul plugin for egg.
Install
$ npm i egg-consul-pro
Configuration
egg-consul-pro
support all configurations in consul.
- promisify:
true
=> Cannot Modify
// {app_root}/config/config.default.js
// Single Consul
exports.consul = {
client: {
host: "127.0.0.1",
port: 7888,
promisify: true,
}
};
// Multi Consul
exports.consul = {
clients: {
instance1: {
host: "127.0.0.1",
port: 7888,
promisify: true,
},
instance2: {
host: "127.0.0.1",
port: 7888,
promisify: true,
},
}
};
Usage
// {app_root}/app.js
class AppBootHook {
constructor (app) {
this.app = app;
}
async didLoad () {
// Single Consul
if (this.app.consul) {
this.app.consul.client; // consul client
this.app.consul.getNodes("serviceName","tag").then(nodes => {
console.log(nodes);
});
this.app.consul.on("serviceChange", ({serviceName,tag,nodes}) => {
console.log(serviceName,tag,nodes);
});
}
}
}
module.exports = AppBootHook;
Questions & Suggestions
Please open an issue here.