Code Monkey home page Code Monkey logo

egg-grpc-client's Introduction

@142vip/egg-grpc-client

可能有用

支持的功能

  • 支持单个grpc-server服务端连接实例
  • 支持多个grpc-server服务端连接实例
  • 灵活配置app、agent挂载,灵活使用egg.js全局对象
  • 详细的日志报警机制,支持日志切割与划分

安装

## 安装最新版grpc-client插件
npm i @142vip/egg-grpc-client --save
## 安装制定版本grpc-client插件
npm i @142vip/egg-grpc-client@xxx --save

快速使用

在plugin.js插件配置文件中配置egg-grpc-client

// {app_root}/config/plugin.js
exports.grpcClient = {
  enable: true,
  package: '@142vip/egg-grpc-client',
};

默认配置

// {app_root}/config/config.default.js
exports.grpcClient = {
    // 默认配置,会填充到每个连接实例中
    app: true,
    agent: false,
    // 支持单个grpc-server连接实例
    client: {
      protoDir: 'app/grpc',
      serviceDir: 'app/grpc',
      host: '127.0.0.1',
      port: '50051',
      loaderOptions: {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true,
      },
    },
    // 支持多个grpc-server连接实例
    clients: {
      gprc_go: {
        protoDir: 'app/grpc',
        serviceDir: 'app/grpc',
        host: '127.0.0.1',
        port: '50051',
        loaderOptions: {
          keepCase: true,
          longs: String,
          enums: String,
          defaults: true,
          oneofs: true,
        },
      },
      grpc_test: {
        protoDir: 'app/grpc',
        serviceDir: 'app/grpc',
        host: '127.0.0.1',
        port: '50051',
        loaderOptions: {
          keepCase: true,
          longs: String,
          enums: String,
          defaults: true,
          oneofs: true,
        },
      },
    },
};

更多默认配置,请查看config/config.default.js

使用示例

// 连接单个grpc server时

ctx.grpcClient.xxx

// 连接多个grpc server用例时
ctx.grpcClient.get('xxx').xxxx

完整grpc客户端、服务端插件使用示例,可以参考egg-grpc-client/example

证书

MIT License

Copyright (c) 2022 142vip FairySister Rong姐姐好可爱

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

egg-grpc-client's People

Contributors

chufan443 avatar mmdapl avatar

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.