项目作者: AkashBabu

项目描述 :
gRPC Pool Connection for Nodejs Clients
高级语言: JavaScript
项目地址: git://github.com/AkashBabu/lib-grpc-client-pool.git
创建时间: 2018-07-01T15:06:14Z
项目社区:https://github.com/AkashBabu/lib-grpc-client-pool

开源协议:MIT License

下载


grpc-pool Build Status Maintainability

A light-weight efficient implementation for gRPC connection pool.
For detailed documentation please visit this wiki

What’s new in 1.4.0 ?

  • Support for statically generated code(protobuf) files

Example

Naming Rules in Proto Files

Names of the RPC function must Match /^[A-Z]/, meaning it must start with an `followed by an Upper-Case letter Sample.proto` file:

  1. syntax = "proto3";
  2. package Hello;
  3. service Greeting {
  4. rpc NotAvailable(Request) returns (Reply) {};
  5. rpc _Hi(Request) returns (Reply) {};
  6. }
  7. message Request {
  8. string msg = 1;
  9. }
  10. message Reply {
  11. string resp = 1;
  12. }

** Note that the RPC NotAvailable will not be exposed by this library

  1. const PROTO_FILE_PATH = path.join(__dirname, 'hello_grpc_pb');
  2. const client = new GRPCClient(PROTO_FILE_PATH, {
  3. maxConnections : 5,
  4. packageName : 'Hello',
  5. serviceName : 'Greeting',
  6. url : 'localhost:50001',
  7. prefix : 'RPC'
  8. });
  9. const { RPC_Hi } = client;
  10. const response = await RPC_Hi({msg: 'Hey Bot!'})

Usage with statically generated code (protobuf)

Note: You must use the same naming convention mentioned for the above protobuf file

  1. const PROTO_FILE_PATH = path.join(__dirname, 'hello_grpc_pb');
  2. const client = new GRPCClient(PROTO_FILE_PATH, {
  3. maxConnections : 2,
  4. rpcPrefix : 'RPC',
  5. serviceName : 'Greeting',
  6. url : 'localhost:50001',
  7. staticFile : true,
  8. });
  9. const { RPC_Hi } = client;
  10. const request = new messages.Request();
  11. request.setMsg('Hi');
  12. const res = await RPC_Hi(request);
  13. expect(res.getResp()).to.be.eql('Hello');

Notice the usage of staticFile flag. Also notice that packageName is not needed when static file is being used.

Installation

npm i lib -S

ES-Lint

npm run lint

Babel

npm run build

Mocha & Chai (Testing)

npm test

Coverage Report

npm run coverage

Contributions

This is open-source, which makes it obvious for any PRs, but I would request you to add necessary test-cases for the same