{"id":13781711,"url":"https://github.com/Julien-R44/adonis-grpc-consumer","last_synced_at":"2025-05-11T15:31:58.002Z","repository":{"id":41602344,"uuid":"440570054","full_name":"Julien-R44/adonis-grpc-consumer","owner":"Julien-R44","description":"🕸️ Adonis gRPC client provider for easily communicate with gRPC services.","archived":false,"fork":false,"pushed_at":"2022-04-29T13:31:52.000Z","size":249,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-27T03:35:07.947Z","etag":null,"topics":["adonisjs","grpc","grpc-client"],"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/Julien-R44.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Julien-R44"]}},"created_at":"2021-12-21T15:49:09.000Z","updated_at":"2024-08-12T19:09:45.000Z","dependencies_parsed_at":"2022-08-10T04:50:50.354Z","dependency_job_id":null,"html_url":"https://github.com/Julien-R44/adonis-grpc-consumer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fadonis-grpc-consumer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fadonis-grpc-consumer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fadonis-grpc-consumer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fadonis-grpc-consumer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Julien-R44","download_url":"https://codeload.github.com/Julien-R44/adonis-grpc-consumer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253588589,"owners_count":21932284,"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":["adonisjs","grpc","grpc-client"],"created_at":"2024-08-03T18:01:28.500Z","updated_at":"2025-05-11T15:31:57.703Z","avatar_url":"https://github.com/Julien-R44.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Julien-R44"],"categories":["Packages"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://i.imgur.com/iiuiVlq.png\" width=\"250px\" /\u003e  \n  \u003cbr/\u003e\n  \u003ch3\u003eAdonis gRPC Consumer\u003c/h3\u003e\n  \u003cp\u003eCommunicate easily with gRPC services in Adonis\u003c/p\u003e\n  \u003ca href=\"https://www.npmjs.com/package/adonis-grpc-consumer\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/adonis-grpc-consumer.svg?style=for-the-badge\u0026logo=npm\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/npm/l/adonis-grpc-consumer?color=blueviolet\u0026style=for-the-badge\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\" /\u003e\n\u003c/div\u003e\n\n## Installation\n\n```\nnpm i adonis-grpc-consumer\nnode ace configure adonis-grpc-consumer\n```\n\n## Usage Example\n\nFirst of all, you need to create a \"proto\" folder at the root of your Adonis project in which you will obviously store your protobuf definition files.\n\nmy-app/proto/myService.proto :\n```protobuf\nsyntax = \"proto3\";\npackage my_service;\n\nmessage Empty {}\nservice MyService {\n  rpc SendMessage (SendMessageRequest) returns (Empty) {};\n}\n\nmessage SendMessageRequest {\n  string message = 1;\n}\n```\n\nNow you have to generate the type definitions for typescript. To do this, run :\n```\nnpx build-proto --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=./proto/ ./proto/*.proto\n```\n`build-proto` is an executable from `@grpc/proto-loader` package ( `proto-loader-gen-types` ) that is embedded in `adonis-grpc-consumer`.\n\nIf everything went well, in my-app/proto/ you should find your TS definition files next to your .proto file.\n\nNow we go back to Adonis, we will add our freshly created service as a consumable service, in config/grpc-consumer.ts : \n```typescript\nlet grpcConfig: GrpcConsumerConfig = {\n  verbose: true,\n  clients: [\n    {\n      name: 'MY_SERVICE',\n      options: {\n        package: 'my_service',\n        serviceName: 'MyService',\n        protoPath: path.join(__dirname + '/../proto/myService.proto'),\n        url: '127.0.0.1:4545', // Don't forget to add your service url here\n      },\n    },\n  ],\n}\n\nexport default grpcConfig\n```\n\nTry to launch your application, in case everything went well, you should see the following message (only with `verbose: true`):\n```\n[GRPC] Client MY_SERVICE connected !\n```\n\nTo use our service and call the `SendMessage` function defined in the protobuf file, we do the following: \n\n```typescript\nimport GrpcConsumer, { grpc } from '@ioc:Adonis/Addons/GrpcConsumer'\nimport { MyServiceClient } from 'proto/my_service/MyService'\n\nconst client = GrpcConsumer.getClient\u003cMyServiceClient\u003e('MY_SERVICE')\nclient.SendMessage({ message: 'hello !' }, (error?: grpc.ServiceError) =\u003e {\n    if (error) {\n      console.error(error.message)\n    }\n  }\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJulien-R44%2Fadonis-grpc-consumer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJulien-R44%2Fadonis-grpc-consumer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJulien-R44%2Fadonis-grpc-consumer/lists"}