Giter Site home page Giter Site logo

egg-consul-plus's Introduction

ht-egg-consul

Fork: https://github.com/iamljw/egg-consul-plus

依赖说明

依赖的 egg 版本

ht-egg-consul 版本 | egg 2.x

依赖的插件

安装插件

$ npm i ht-egg-consul
// 或者
$ yarn add ht-egg-consul

开启插件

// config/plugin.js
exports.consulPlus = {
  enable: true,
  package: 'ht-egg-consul',
};

使用场景

  • Why and What: 基于 consul 开发的 egg 插件,实现服务的自动注册和发现,多实例模式和简单的负载均衡、服务熔断。
  • How: 开启插件后会在当前应用实例 app 上挂载 consul 客户端和 services 服务列表,分别用app.consulapp.services进行引用。 注意:当开启多实例(multiInstance为true),app.services.referName会切换为异步获取,返回值为Promise对象

详细配置

consul: {
    configFileType: 'yaml' // 用户配置文件类型 yaml | json 默认 json
    server: {
        host: '127.0.0.1', // 注册中心ip地址
        port: 8500 // 注册中心端口号
    },
    services: [ // 服务发现列表
        {
            referName: 'consulPlusTest', // 引用名,后续可用 app.services.referName 访问服务
            comment: 'consulPlusTest', // 备注
            serviceId: 'consul-plus-test' // 服务id
        }
    ],
    register: true, // 是否注册当前模块,默认为false
    multiInstance: true, // 多实例模式开关,默认为false,注意当开启多实例,务必保证集群中的每个项目的keys不同,或者会导致先启动的项目被隔离(被覆盖)
    name: 'consul-plus-test', // 注册id
    tags: ['consul-plus-test'], // 标签信息
    check: {
        http: 'http://127.0.0.1:7777', // 健康检测地址
        interval: '5s', // 健康检测间隔
        notes: 'http service check',
        status: 'critical'
    },
    address: '127.0.0.1', // 当前模块的注册地址
    port: 7777 // 当前模块的注册端口号
}

单元测试

提问交流

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.