npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-xeureka

v1.1.3

Published

register egg application to eureka

Downloads

4

Readme

egg-eureka-plugin

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-eureka-plugin --save

Usage

// {app_root}/config/plugin.js
exports.eureka = {
  enable: true,
  package: 'egg-eureka-plugin',
};

Configuration

// {app_root}/config/config.default.js
// 熔断配置
exports.circuitBreaker = {
  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配置
exports.apiClient = {
  // 通过egg apiclient 完成对微服务信息的订阅功能
  subscribe: {
    // 自定义foo,作为在service中获取订阅信息的key值
    foo: {
      // bar 是你需要订阅的微服务的vipAddress,一般和app name相同
      // 填写后agent会在registryUpdated事件触发时更新微服务实例信息,并发布给各个follwer
      dataId: 'bar',
    },
  },
};

// eureka配置
exports.eureka = {
  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.exports = app => {
  class accountService extends app.Service {
    constructor(ctx) {
      super(ctx);
      this.appId = 'foo';
    }
    _getServerUrl() {
      const eurekaUtil = this.ctx.app.eurekaUtil;
      const instances = this.ctx.app.apiClient.get(this.appId);
      if (!Array.isArray(instances) || instances.length === 0) {
        // this.ctx.logger.error('get 0 instances!!');
        this.ctx.throw('get 0 instances!!');
      }
      const ins = eurekaUtil.getOneInstanceFromAll(instances);
      const serverUrl = eurekaUtil.getServerPath(ins);

      return serverUrl;
    }

    async account(userId) {
      const url = `${this._getServerUrl()}/account/${userId}`;
      return await this.breakerRequest(url);
    }
  }
  return accountService;
};


## Questions & Suggestions

Please open an issue [here](https://github.com/HOTTIN/egg-eureka/issues).

## License

[MIT](LICENSE)