Skip to content

hm496/egg-consul-pro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published