Registry / devops / egg-grpc

egg-grpc

JSON →
library1.0.3jsnpmunverified

gRPC plugin for the Egg.js framework (version 1.0.3). Integrates gRPC client functionality into Egg applications by automatically loading protocol buffer files from a configurable directory, attaching service stubs to ctx and app objects. Supports proto file discovery, name conversion between protobuf conventions and JavaScript, and unary RPC calls. Requires Egg.js and gRPC dependencies. Last updated in 2018 and appears to be in maintenance mode with no recent activity.

npm install egg-grpc
INSTALL
IMPORT
SIG · EGG-GRPC
E
egg-grpc
devopsjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

exports.grpc
exports.grpc = { enable: true, package: 'egg-grpc' }
module.exports.grpc = ...
Configure in config/plugin.js using plugin syntax
config.grpc
exports.grpc = { endpoint: 'localhost:50051' }
module.exports.grpc = ...
Configure endpoint and options in config/config.default.js
ctx.grpc
const client = ctx.grpc.packageName.serviceName.rpcName
ctx.grpc()
Access gRPC client methods via ctx.grpc.<package>.<service>.<rpc> (camelCase)
app.grpcProto
const msg = new app.grpcProto.packageName.MessageName({...})
app.grpc.messageClass
Proto message classes are on app.grpcProto, not app.grpc

Shows how to enable the plugin, configure endpoint, and make a unary gRPC call from a controller using the client attached to ctx.

// {app_root}/config/plugin.js exports.grpc = { enable: true, package: 'egg-grpc', }; // {app_root}/config/config.default.js exports.grpc = { endpoint: 'localhost:50051', // gRPC server address // dir: 'app/proto', // default directory for .proto files // property: 'grpc', // default property name on ctx }; // Assume app/proto/share.proto with: // package egg.share; // service ShowCase { rpc Echo(Status) returns (Status); } // message Status { string code = 1; string err_msg = 2; } // In a controller or service (using async/await or generator): const client = ctx.grpc.egg.share.showCase; const result = await client.echo({ code: '200' }); console.log(result); // { code: '200', err_msg: '' }
Debug
Known issues
deprecatedThe legacy grpc package is deprecated; use @grpc/grpc-js instead.
fix
Switch to a more modern gRPC plugin or adjust the plugin to use @grpc/grpc-js.
affects: <=1.0.3
breakingThis plugin uses the full 'grpc' package, which is not compatible with @grpc/grpc-js in some cases.
fix
If you need @grpc/grpc-js, you must fork or rewrite the plugin.
affects: <=1.0.3
gotchaProto file paths do not affect the namespace on ctx; only the proto package definition matters.
fix
Use the package name as defined in .proto files, not the file path.
affects: all
gotchaService and rpc names are converted to camelCase when accessed via ctx.grpc.
fix
For service ShowCase, access as ctx.grpc.egg.share.showCase, not ShowCase.
affects: all
gotchaYou cannot call rpcs via app.grpc; use ctx.grpc for invoking RPCs (app.grpcProto is for message constructors).
fix
Use ctx.grpc for making RPC calls, not app.grpc.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
grpc package is not installed or not listed in dependencies.
fix
npm install grpc --save (note: grpc is deprecated).
TypeError: ctx.grpc is undefined
egg-grpc plugin not enabled or not properly configured.
fix
Ensure config/plugin.js has exports.grpc = { enable: true, package: 'egg-grpc' } and the package is installed.
Error: ENOENT: no such file or directory, open '...'
The proto directory specified in config.grpc.dir does not exist.
fix
Create the directory or update the config to point to an existing directory.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
eggrequiredEgg.js framework plugin, requires Egg application
grpcrequiredgRPC client library for Node.js (the legacy grpc package)
Agent activity
6 hits · last 30 days
node
6
Resources
egg-grpc — npm install egg-grpc · libregistry