{"id":18941438,"url":"https://github.com/mchmarny/grpc-sample","last_synced_at":"2025-08-24T04:07:56.467Z","repository":{"id":57496448,"uuid":"205000031","full_name":"mchmarny/grpc-sample","owner":"mchmarny","description":"Sample gRPC service on Cloud Run","archived":false,"fork":false,"pushed_at":"2023-02-24T22:57:24.000Z","size":19372,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T22:42:50.507Z","etag":null,"topics":["cloudrun","gcp","golang","grpc","knative","protobuf"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mchmarny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-28T18:42:05.000Z","updated_at":"2020-01-24T23:30:27.000Z","dependencies_parsed_at":"2024-06-20T12:03:30.817Z","dependency_job_id":null,"html_url":"https://github.com/mchmarny/grpc-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgrpc-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgrpc-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgrpc-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgrpc-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mchmarny","download_url":"https://codeload.github.com/mchmarny/grpc-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239942596,"owners_count":19722328,"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":["cloudrun","gcp","golang","grpc","knative","protobuf"],"created_at":"2024-11-08T12:28:03.832Z","updated_at":"2025-02-21T01:40:18.495Z","avatar_url":"https://github.com/mchmarny.png","language":"Go","readme":"# grpc-sample\n\n\nThis sample app walks though setting [gRPC](https://grpc.io/) service on Cloud Run. This functionality is still experimental so some of the implementation may still change.\n\n\u003e Note, to keep this readme short, I will be asking you to execute scripts rather than listing here complete commands. You should really review each one of these scripts for content, and, to understand the individual commands so you can use them in the future.\n\n## Pre-requirements\n\n### GCP Project and gcloud SDK\n\nIf you don't have one already, start by creating new project and configuring [Google Cloud SDK](https://cloud.google.com/sdk/docs/). Similarly, if you have not done so already, you will have [set up Cloud Run](https://cloud.google.com/run/docs/setup).\n\n## Setup\n\nTo setup this service you will need to clone this repo:\n\n```shell\ngit clone https://github.com/mchmarny/logo-identifier.git\n```\n\nAnd navigate into that directory:\n\n```shell\ncd logo-identifier\n```\n\n## API Definition\n\nFirst, you need to define the API, the shape of the payload that will be exchange between client and the server. Do define the Services and Messages you must use [Protocol Buffers](https://developers.google.com/protocol-buffers/) (Protobuf) which is a language-neutral mechanism for serializing structured data.\n\nThe `proto` file I will use in this example is located in [api/v1/message.proto](api/v1/message.proto) and it looks like this:\n\n```protobuf\nsyntax = \"proto3\";\n\npackage message;\n\nimport \"google/protobuf/timestamp.proto\";\n\nservice MessageService {\n  rpc Send(Request) returns (Response) {}\n  rpc SendStream(stream Request) returns (stream Response) {}\n}\n\nmessage Request {\n  string message = 1;\n}\n\nmessage Content {\n  int32 index = 1;\n  string message = 2;\n  google.protobuf.Timestamp received_on = 3;\n}\n\nmessage Response {\n  Content content = 1;\n}\n```\n\nThe content should be pretty self-explanatory. It basically describes the Request and Response, the Content message that both of these use, and the two methods: Send with unary request and response as well as SendStream with unary request and stream response. To learn more about setting up Protobuf see `go` support doc [here](https://github.com/golang/protobuf).\n\n\nTo auto-generate the `go` code from that `proto` run [bin/api](bin/api) script\n\n\n```shell\nbin/api\n```\n\nAs a result, you should now have a new `go` file titled [pkg/api/v1/message.pb.go](pkg/api/v1/message.pb.go). You can review that file but don't edit it as it will be overwritten the next time we run the [bin/api](bin/api) script\n\n\n## Container Image\n\nNext, build the server container image which will be used to deploy Cloud Run service using the [bin/image](bin/image) script\n\n```shell\nbin/image\n```\n\n## Service Account\n\nNow create a service account and assign it the necessary roles using the [bin/user](bin/user) script\n\n```shell\nbin/user\n```\n\n## Service Deployment\n\nOnce the container image and service account are ready, you can now deploy the new service using [bin/deploy](bin/deploy) script\n\n```shell\nbin/deploy\n```\n\n## Build Client\n\nTo invoke the deployed Cloud Run service, build the gRPC client using the [bin/client](bin/client) script\n\n```shell\nbin/client\n```\n\nThe resulting CLI will be compiled into the `bin` directory. The output of the [bin/client](bin/client) script will also print out the two ways you can execute that client\n\n```shell\nClient CLI generated.\nUsage:\n Unary Request/Unary Response\n bin/cli --server grpc-sample-***-uc.a.run.app:443 --message hi\n\n Unary Request/Stream Response\n bin/cli --server grpc-sample-***-uc.a.run.app:443 --message hi --stream 5\n```\n\n### Testing Service on Cloud Run\n\nWhen executing the built CLI in unary way (by not including the `--stream` flag) you will see the details of the sent and received message\n\n```shell\nUnary Request/Unary Response\n Sent:\n  hi\n Response:\n  content:\u003cindex:1 message:\"hi\" received_on:\u003cseconds:1567098976 nanos:535796117 \u003e \u003e\n```\n\nWhere as executing it using stream (with `--stream` number) the CLI will print the sent message index and server processing time\n\n```shell\nUnary Request/Stream Response\n  Stream[1] - Server time: 2019-08-29T17:16:22.837297811Z\n  Stream[2] - Server time: 2019-08-29T17:16:22.837928885Z\n  Stream[3] - Server time: 2019-08-29T17:16:22.83794915Z\n  Stream[4] - Server time: 2019-08-29T17:16:22.837959711Z\n  Stream[5] - Server time: 2019-08-29T17:16:22.837968925Z\n```\n\n## Disclaimer\n\nThis is my personal project and it does not represent my employer. I take no responsibility for issues caused by this code. I do my best to ensure that everything works, but if something goes wrong, my apologies is all you will get.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Fgrpc-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmchmarny%2Fgrpc-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Fgrpc-sample/lists"}