GRPC helper
WARNING: in beta !!!
Getting Started
Installing
npm i grpc-helper --save
or
yarn add grpc-helper
Features
- Promised unary & client stream call
- Client Load balance
- Service health checking
- Service discovery (static, dns srv)
- Circuit breaker
Usage
DNS Service discovery
const helper = new GRPCHelper({
packageName: 'helloworld',
serviceName: 'Greeter',
protoPath: path.resolve(__dirname, './hello.proto'),
sdUri: 'dns://_http._tcp.greeter',
});
await helper.waitForReady();
const res = await helper.SayHello({
name: 'foo',
});
Static Service discovery
const helper = new GRPCHelper({
packageName: 'helloworld',
serviceName: 'Greeter',
protoPath: path.resolve(__dirname, './hello.proto'),
sdUri: 'static://localhost:50051,localhost:50052,localhost:50053',
});
await helper.waitForReady();
const res = await helper.SayHello({
name: 'foo',
});
Resolve with full response
const helper = new GRPCHelper({
packageName: 'helloworld',
serviceName: 'Greeter',
protoPath: path.resolve(__dirname, './hello.proto'),
sdUri: 'static://localhost:50051',
resolveFullResponse: true,
});
await helper.waitForReady();
const { message, peer, status, metadata } = await helper.SayHello({
name: 'foo',
});
Client stream call
const stream = new stream.PassThrough({ objectMode: true });
const promise = helper.SayMultiHello(stream);
stream.write({
name: 'foo1',
});
stream.write({
name: 'foo2',
});
stream.write({
name: 'foo3',
});
stream.end();
const result = await promise;
TODO
License
This project is licensed under the MIT License - see the LICENSE file for details