egg-consul-pro

0.0.1 • Public • Published

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.

License

MIT

Package Sidebar

Install

npm i egg-consul-pro

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

5.53 kB

Total Files

7

Last publish

Collaborators

  • hm496