Registry / devops / egg-etcd-grpc

egg-etcd-grpc

JSON →
library1.0.8jsnpmunverified

An Egg.js plugin that provides gRPC client integration with etcd for service discovery. It enables Egg.js applications to dynamically resolve gRPC service endpoints from etcd, load .proto files, and make gRPC calls. Version 1.0.8, released as needed on GitHub. Differentiates by tight integration with Egg.js lifecycle and configuration patterns, supporting multiple gRPC services per app with auto-reconnection. Requires Node >=16.

npm install egg-etcd-grpc
INSTALL
IMPORT
SIG · EGG-ETCD-GRPC
E
egg-etcd-grpc
devopsjavascriptv1.0.8
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.

egg-etcd-grpc
// In config/plugin.js: exports.etcdGrpc = { enable: true, package: 'egg-etcd-grpc' };
require('egg-etcd-grpc') // CommonJS require is not used; plugin is loaded via Egg.js config.
Egg.js plugins are loaded via plugin config, not direct import. The package name is used in plugin.js.
app.grpcClient
app.grpcClient.demoRpc.passport.profile.ProfileService.getUserInfo({userId: '...'})
app.grpcClient['demoRpc']['passport.profile']['ProfileService'].getUserInfo(...) // Incorrect path: dots are not segmented.
Service names follow proto package hierarchy with dots; access using dot notation on the grpcClient object.
exports.etcdGrpc
// In config/config.default.js: exports.etcdGrpc = { ... };
module.exports = { etcdGrpc: { ... } } // Egg uses exports.* pattern, not module.exports.
Configuration is added as property on exports object per Egg.js convention.

Activates the Egg.js plugin, configures a gRPC client with etcd service discovery, and makes a gRPC call from a controller.

// {app_root}/config/plugin.js exports.etcdGrpc = { enable: true, package: 'egg-etcd-grpc', }; // {app_root}/config/config.default.js exports.etcdGrpc = { demoRpc: { etcd: { hosts: [process.env.ETCD_HOSTS ?? '127.0.0.1:2379'], key: "demo.rpc", auth: { username: process.env.ETCD_USERNAME ?? '', password: process.env.ETCD_PASSWORD ?? '', } }, grpc: { loaderOption: { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true }, protoPath: 'app/grpc/demo', deadline: 1000, } } }; // In a controller: class HomeController extends Controller { async index() { const ctx = this.ctx; const userInfo = await ctx.app.grpcClient.demoRpc.passport.profile.ProfileService.getUserInfo({ userId: '230371e2-eb07-4b2b-aa61-73fd27c5387e' }); ctx.body = userInfo; } }
Debug
Known issues
gotchaService discovery relies on etcd key being exactly as registered by the server. Mismatched keys cause 'no such service' errors.
fix
Ensure the etcd key in config matches the key used by the gRPC server when registering its endpoint.
affects: >=0.0.0
gotchaThe plugin uses the `grpc` npm package (gRPC C-core), not `@grpc/grpc-js`. This may cause compatibility issues in some environments (e.g., Alpine Linux) and is slower to install.
fix
If possible, switch to a package that uses @grpc/grpc-js, or ensure your environment supports native modules.
affects: >=0.0.0
gotchaThe `loaderOption.longs` is set to `String` by default, which converts Long types to strings. If you need numeric operations on long values, this will cause silent failures or type errors.
fix
Change `loaderOption.longs` to `Number` or use a custom function if you need JavaScript Number (with precision loss) or keep as Long object.
affects: >=0.0.0
gotchaThe `deadline` option is in milliseconds, not seconds. Setting it too low may cause frequent DEADLINE_EXCEEDED errors.
fix
Set deadline to at least 10,000 ms for typical RPCs, or adjust based on your service latency.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'egg-etcd-grpc'
Plugin not installed via npm.
fix
Run `npm install egg-etcd-grpc --save` in your project root.
Error: Can not find service in proto files
The proto file path or service name does not match config.
fix
Ensure `config.etcdGrpc.grpc.protoPath` points to a directory containing the .proto files, and the service name in the gRPC call matches exactly (including package).
Error: No such service: <service>
The etcd key does not match the registered gRPC service endpoint.
fix
Verify the service registered in etcd with the same `key` value as in config.etcdGrpc.etcd.key.
TypeError: app.grpcClient.demoRpc is undefined
Plugin is not enabled or configuration is incorrect.
fix
Check that `config/plugin.js` has `exports.etcdGrpc = { enable: true, package: 'egg-etcd-grpc' };` and `config/config.default.js` has `exports.etcdGrpc = { ... };` properly set.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies
eggrequiredPeer dependency; plugin expects Egg.js application context and lifecycle hooks.
grpcrequiredCore gRPC library for making client calls.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
egg-etcd-grpc — npm install egg-etcd-grpc · libregistry