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-rpc4js

v2.2.0

Published

sofa-rpc-node的 egg 插件版本

Downloads

9

Readme

egg-rpc4js

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

依赖说明

依赖的 egg 版本

egg-rpc4js 版本 | egg 1.x --- | --- 1.x | 😁 0.x | ❌

依赖的插件

安装插件

$ npm i egg-rpc4js
或者
$ yarn add egg-rpc4js

开启插件

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

使用场景

  • Why and What: 微服务架构一个主要的问题就是服务间通讯,传统的HttpClient方式性能低、过程复杂,因而采用sofarpc的node版本替代传统方案,sofarpc实现了服务注册、发现、负载均衡、故障熔断等功能,本项目作为sofa-rpc-node的 egg 插件版本,帮助开发者更快的集成rpc功能。
  • How: 本插件依赖 zookeeper 作为注册中心,应先在本地或服务器上部署 zookeeper,默认启动端口为 2181

详细配置

exports.rpc4js = {
    registry: {
        address: '127.0.0.1:2181' // zookeeper地址 根据实际情况配置
    },
    client: {
        services: [{
            namespace: 'account', // 服务命名空间
            modules: ['wallet', 'security'] // 选择消费该服务下的模块功能
        }],
        responseTimeout: 3000 // 响应超时(单位:ms)
    },
    server: {
        namespace: 'market', // 服务命名空间
        port: 12200 // 监听端口
    }
}

接口实现

rpc应用目录结构:

egg-example
├── app
│   ├── controller // 普通接口实现目录
│   │   └── home.js
|   ├── rpc // RPC接口实现目录
|   |   └── m1.js
|   |   └── m2.js
│   └── router.js
├── config
│   └── config.default.js
└── package.json

实现类:

// ${baseDir}/app/rpc/handler.js
'use strict';

class Handler {
    constructor(app, ctx) {
        this.app = app;
        this.ctx = ctx;
    }

    async getUser() {
        // ...
    }
    // ...
}

module.exports = Handler;

调用RPC服务

// ...
await ctx.rpc.namespace.module.interfaceName(...args);
// 或者
await app.rpc.namespace.module.interfaceName(...args);
/**
 * 说明
 * namespace 为服务命名空间
 * module 为该服务提供的rpc模块
 * interfaceName 为该模块的接口
 * 
 * 请在使用中根据实际情况进行替换
 * /

单元测试

提问交流

请到 egg-rpc4js issues 异步交流。

License

MIT