{"id":25428250,"url":"https://github.com/xizhibei/grpc-helper","last_synced_at":"2025-10-31T17:30:33.057Z","repository":{"id":32951462,"uuid":"146169870","full_name":"xizhibei/grpc-helper","owner":"xizhibei","description":"An improved gRPC client with lots of helpful features.","archived":false,"fork":false,"pushed_at":"2022-12-08T19:13:59.000Z","size":813,"stargazers_count":81,"open_issues_count":12,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-17T04:42:26.708Z","etag":null,"topics":["grpc","grpc-client","load-balance","node-grpc","promise-api","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xizhibei.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-26T10:06:01.000Z","updated_at":"2024-09-10T06:07:07.000Z","dependencies_parsed_at":"2023-01-14T22:48:18.057Z","dependency_job_id":null,"html_url":"https://github.com/xizhibei/grpc-helper","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xizhibei%2Fgrpc-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xizhibei%2Fgrpc-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xizhibei%2Fgrpc-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xizhibei%2Fgrpc-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xizhibei","download_url":"https://codeload.github.com/xizhibei/grpc-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239221263,"owners_count":19602378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","grpc-client","load-balance","node-grpc","promise-api","typescript"],"created_at":"2025-02-17T01:38:22.877Z","updated_at":"2025-10-31T17:30:33.018Z","avatar_url":"https://github.com/xizhibei.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRPC helper\n\ngRPC helper is an improved gRPC client with lots of helpful features.\n\n[![Build Status](https://travis-ci.org/xizhibei/grpc-helper.svg?branch=master\u0026style=flat)](https://travis-ci.org/xizhibei/grpc-helper)\n[![Coverage Status](https://coveralls.io/repos/github/xizhibei/grpc-helper/badge.svg?branch=master)](https://coveralls.io/github/xizhibei/grpc-helper?branch=master)\n[![npm version](https://badge.fury.io/js/grpc-helper.svg?style=flat)](http://badge.fury.io/js/grpc-helper)\n[![Dependency Status](https://img.shields.io/david/xizhibei/grpc-helper.svg?style=flat)](https://david-dm.org/xizhibei/grpc-helper)\n[![npm](https://img.shields.io/npm/l/grpc-helper.svg)](https://github.com/xizhibei/grpc-helper/blob/master/LICENSE)\n\n### Getting Started\n\n### Installing\n\n```bash\nnpm i grpc-helper --save\n```\n\nor\n\n```bash\nyarn add grpc-helper\n```\n\n### Features\n\n- Promised unary \u0026 client stream call\n- Client Load balance\n- Service health checking\n- Service discovery (static, dns srv)\n- Circuit breaker based on [Brakes](https://github.com/awolden/brakes)\n- Retry based on [async-retry](https://github.com/zeit/async-retry)\n- Metrics for [prometheus](https://prometheus.io/) based on [prom-client](https://github.com/siimon/prom-client)\n- Highly custom [options](src/common.ts)\n\n### Usage\n\n#### DNS Service discovery\n```ts\nconst helper = new GRPCHelper({\n  packageName: 'helloworld',\n  serviceName: 'Greeter',\n  protoPath: path.resolve(__dirname, './fixtures/hello.proto'),\n  // intervalMs will determine how frequent the resolver lookup the records\n  sdUri: 'dns://_grpc._tcp.greeter?intervalMs=5000',\n});\n\nawait helper.waitForReady();\n\nconst res = await helper.SayHello({\n  name: 'foo',\n});\n```\n\n#### Static Service discovery\n```ts\nconst helper = new GRPCHelper({\n  packageName: 'helloworld',\n  serviceName: 'Greeter',\n  protoPath: path.resolve(__dirname, './fixtures/hello.proto'),\n  sdUri: 'static://localhost:50051,localhost:50052,localhost:50053',\n});\n\nawait helper.waitForReady();\n\nconst res = await helper.SayHello({\n  name: 'foo',\n});\n```\n\n#### Resolve with full response\n```ts\nconst helper = new GRPCHelper({\n  packageName: 'helloworld',\n  serviceName: 'Greeter',\n  protoPath: path.resolve(__dirname, './fixtures/hello.proto'),\n  sdUri: 'static://localhost:50051',\n  resolveFullResponse: true,\n});\n\nawait helper.waitForReady();\n\nconst { message, peer, status, metadata } = await helper.SayHello({\n  name: 'foo',\n});\n```\n\n\n#### Client stream call\n```ts\nconst stream = new stream.PassThrough({ objectMode: true });\n\nconst promise = helper.SayMultiHello(stream);\n\nstream.write({\n  name: 'foo1',\n});\n\nstream.write({\n  name: 'foo2',\n});\n\nstream.write({\n  name: 'foo3',\n});\n\nstream.end();\n\nconst result = await promise; // { message: 'hello foo1,foo2,foo3' }\n```\n\n#### Retry\n```ts\nconst helper = new GRPCHelper({\n  packageName: 'helloworld',\n  serviceName: 'Greeter',\n  protoPath: path.resolve(__dirname, './fixtures/hello.proto'),\n  sdUri: 'static://localhost:50051',\n  retryOpts: {\n    enable: true,\n    retries: 5,\n    bailError(err, attempt) {\n      // Just for example !!! It will not retry when code is 2\n      return err.code === 2;\n    },\n  },\n});\n\nawait helper.waitForReady();\n\nawait helper.SayHello({\n  name: 'foo',\n});\n```\n\n\n#### More\n\nPlease take a look at the [test](test/) folder for more examples.\n\n### TODO\n\n- [x] Better api\n- [x] Doc\n- [x] Test code\n- [x] Retry on lb level when error\n- [ ] Auto load proto when only one service available\n- [ ] Consul/etcd/zk service discovery\n\n\n### License\nThis project is licensed under the MIT License - see the LICENSE file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxizhibei%2Fgrpc-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxizhibei%2Fgrpc-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxizhibei%2Fgrpc-helper/lists"}