consul 的 egg 插件
egg-consul-ddz 插件,功能包括:
yarn add egg-consul-ddz
// plugin.jsexports.eggEos = {enable: true,package: "egg-consul-ddz"};
需要在config.*.js 文件中配置以下参数:
consulDdz: {findTime: '1m', // 发现服务的间隔时间server: {host: '10.199.6.35',port: 8500,secure: false,},serviceList: [ // 服务发现列表{referName: 'plutusCore', // 引用名,后续可用 app.services.referName 访问服务service: 'plutus-core', // 服务id},{referName: 'plutusGeneral',service: 'plutus-general',},],register: false, // 是否注册自己的服务,如果不注册则无需配置 client 参数client: {name: 'egg-gateway-eos', // 服务每次id: 'egg-gateway-eos', // 服务Id,可以与名称一致tags: 'egg-gateway-eos', // 标签信息address: '127.0.0.1', // 服务地址port: 8500, // 服务端口号check: {http: '127.0.0.1:7000', // http服务地址interval: '5s', // 健康检测轮询时间timeout: '10s', // 超时时间status: 'critical', // 初始化服务状态},},},
服务注册成功,会将所有服务信息挂载在 application 实例化后的 app 对象 consulServices 属性上,可以通过如下方式获得
// 获得服务信息app.consulServices[referName]