egg-grpc-servers
Install
npm install egg-plugin-grpc-server --save
Usage
// {app_root}/config/plugin.jsexportsgrpcServer = enable: true package: 'egg-grpc-server';
Configuration
// {app_root}/config/config.default.jsexportsgrpcServer = port: 50051 timeOut: 5000 nameSpace: 'egg.node' dir: 'app/protos';
see config/config.default.js for more detail.
Example
- proto文件夹中文件名({app_root}/app/protos/xxx.proto) proto文件中service名(service xxx) grpc文件夹中文件名({app_root}/app/grpc/xxx.js) 三者应当同名
- proto/xxx.proto/service的接口名 grpc/xxx.js接口名 二者应当同名
config.dir
配置目录,默认app/proto
proto 文件,可通过- Protocol Buffers Docs
- 暂未支持流 后续会增加支持
// {app_root}/app/protos/hello.protosyntax = "proto3"; package eggnode; service hello rpc {}; message helloRequest string name = 1; int32 group = 2; message helloResponse int32 code = 1; string message = 2;
this
为egg
的Application
,接受一个参数为请求的request
接口实现, // {app_root}/app/grpc/hello.js'use strict'; exports { return code: 200 message: 'hello ' + requestname + ', you are in ' + requestgroup ;};
单元测试
const assert app = ;const path = ;const PROTO_PATH_HELLO = path;const grpc = ;
Questions & Suggestions
Please open an issue here.