egg-eureka-plugin
Install
$ npm i egg-eureka-plugin --save
Usage
// {app_root}/config/plugin.jsexportseureka = enable: true package: 'egg-eureka-plugin';
Configuration
// {app_root}/config/config.default.js// 熔断配置exportscircuitBreaker = timeout: 30000 // If our function takes longer than 30 seconds, trigger a failure errorThresholdPercentage: 50 // When 50% of requests fail, trip the breaker resetTimeout: 30000 // After 30 seconds, try again.; // 多进程增强模式apiclient配置exportsapiClient = // 通过egg apiclient 完成对微服务信息的订阅功能 subMap: // 自定义foo,作为在service中获取订阅信息的key值 foo: // bar 是你需要订阅的微服务的vipAddress,一般和app name相同 // 填写后agent会在registryUpdated事件触发时更新微服务实例信息,并发布给各个follwer dataId: 'bar' ; // eureka配置exportseureka = client: // instance信息不是必须的,如果你清楚知道自己将要部署的服务信息,可以自行填写, // 如果是部署在docker中,需要自行填写, // 否则,应用会读取服务器信息以及egg应用的启动信息自动填写配置 instance: instanceId: '127.0.0.1:node-rest:7001' app: 'node-rest' hostName: '127.0.0.1' ipAddr: '127.0.0.1' // preferIpAddress: true, // default is false and host will be used. // homePageUrl: 'http://127.0.0.1:7001/info', statusPageUrl: 'http://127.0.0.1:7001/info' // healthCheckUrl: 'http://127.0.0.1:7001/info', port: $: 7001 '@enabled': 'true' // Important, otherwise spring-apigateway cannot find instance of node-rest vipAddress: 'node-rest' // secureVipAddress: 'node-rest', dataCenterInfo: '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo' name: 'MyOwn' // requestMiddleware: (requestOpts, done) => { // requestOpts.auth = { // user: 'admin', // password: '123456', // }; // done(requestOpts); // }, eureka: fetchRegistry: true // host: '127.0.0.1', // port: 3000, // servicePath: '/eureka/apps/', serviceUrls: default: 'http://127.0.0.1:3000/eureka/apps/' 'http://127.0.0.2:3000/eureka/apps/' ssl: false useDns: false fetchMetadata: false preferIpAddress: true // maxRetries: 0, ;
see config/config.default.js for more detail.
Example
插件在app上封装了breakerRequest方法,通过opossum封装了内置ctx.curl 使用时需要从app.Service继承
'use strict'; // const Service = require('egg').Service; module { Service { superctx; thisappId = 'foo'; } { const eurekaUtil = thisctxappeurekaUtil; const instances = thisctxappapiClient; if !Array || instanceslength === 0 // this.ctx.logger.error('get 0 instances!!'); thisctx; const ins = eurekaUtil; const serverUrl = eurekaUtil; return serverUrl; } async { const url = `/account/`; return await this; } return accountService;}; ## Questions & Suggestions Please open an issue herehttps://github.com/HOTTIN/egg-eureka/issues). ## License MITLICENSE