consul plugin for egg.
$ npm i egg-consul-pro
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,
},
}
};
// {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;
Please open an issue here.