// The greeting service definition.serviceGreeter{// Sends a greetingrpcSayHello(HelloRequest)returns(HelloReply){}}// The request message containing the user's name.messageHelloRequest{stringname=1;}// The response message containing the greetingsmessageHelloReply{stringmessage=1;}
如要搭配 API Gateway 使用 gRPC,您必須提供服務設定以及服務定義。這會設定服務的執行階段行為,包含驗證、服務中的 API、從 HTTP 要求到 gRPC 方法的對應,以及特殊的 API Gateway 設定。
轉碼
API Gateway 會為 Cloud Run 上的 gRPC 服務提供通訊協定轉譯,讓用戶端可使用 HTTP/JSON 透過 API Gateway 與 gRPC 服務進行通訊。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-03 (世界標準時間)。"],[[["\u003cp\u003egRPC is a high-performance, open-source RPC framework that allows client applications to directly call methods on a server application as if they were local objects.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway for gRPC enhances gRPC services by offering API management features such as monitoring, hosting, tracing, and authentication.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway can translate RESTful JSON over HTTP into gRPC requests, enabling flexibility by supporting both gRPC and JSON/HTTP clients.\u003c/p\u003e\n"],["\u003cp\u003egRPC services use protocol buffers as the Interface Definition Language (IDL) to define services, methods, parameters, and return types, and require a service configuration for runtime behavior.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway supports protocol translation for gRPC services, enabling HTTP/JSON clients to interact with gRPC services, but payload compression and IDLs other than protocol buffers are not currently supported.\u003c/p\u003e\n"]]],[],null,["# gRPC overview\n=============\n\n[gRPC](http://www.grpc.io) is a high performance, open-source universal RPC\nframework, developed by Google. In gRPC, a client application can directly call\nmethods on a server application on a different machine as if it was a local\nobject, making it easier to create distributed applications and services.\n\nOne of the primary benefits of using gRPC is for documentation; you can use\nyour service configuration and API interface definition files to generate\nreference documentation for your API.\n\nAPI management\n--------------\n\nWith API Gateway for gRPC, you can use the API management\ncapabilities of API Gateway to add monitoring,\nhosting, tracing, authentication, and more to your gRPC services on Cloud Run. In addition,\nonce you specify special mapping rules, API Gateway translates RESTful JSON over HTTP\ninto gRPC requests. This means that you can deploy a gRPC server managed by\nAPI Gateway and call its API using a gRPC or JSON/HTTP client,\ngiving you much more flexibility and ease of integration with other systems.\n\nYou can create gRPC services for API Gateway in any gRPC-supported language. You can find out much more about gRPC,\nincluding quickstarts and tutorials for creating servers and clients, on the\n[gRPC site](http://www.grpc.io/docs/).\n\nService definition and configuration\n------------------------------------\n\ngRPC is based on the idea of defining a **service** , specifying the methods\nthat can be called remotely with their parameters and return types. By default,\ngRPC uses [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview)\nas the Interface Definition Language (IDL) for describing both the service\ninterface and the structure of the payload messages. \n\n // The greeting service definition.\n service Greeter {\n // Sends a greeting\n rpc SayHello (HelloRequest) returns (HelloReply) {}\n }\n\n // The request message containing the user's name.\n message HelloRequest {\n string name = 1;\n }\n\n // The response message containing the greetings\n message HelloReply {\n string message = 1;\n }\n\nTo use gRPC with API Gateway, you must provide a\n[service configuration](/api-gateway/docs/grpc-service-config)\nalong with the service definition. This configures the runtime\nbehavior of your service, including authentication, the API(s) included in the\nservice, mappings from HTTP requests to gRPC methods, and special API Gateway settings.\n\nTranscoding\n-----------\n\nAPI Gateway provides protocol translation for your gRPC services on Cloud Run\nallowing clients to use HTTP/JSON to communicate with a gRPC service through the API Gateway.\n\nThe most common use case is allowing browser clients to talk to gRPC servers\nwithout special support from gRPC client libraries. API Gateway\nprovides a mechanism for mapping HTTP requests to gRPC methods as part of\n[service configuration](/api-gateway/docs/grpc-service-config).\n\nYou can find out more about this in [Transcoding HTTP/JSON to gRPC](/endpoints/docs/grpc/transcoding).\n| **Note** : When using gRPC transcoding, request and response body sizes exceeding **one megabyte** may result in `500 Internal Server Error` responses.\n|\n| If this size is exceeded, request logs for API Gateway will show\n| *grpc_json_transcode_failure{request_buffer_size_limit_reached}*\n| or *grpc_json_transcode_failure{response_buffer_size_limit_reached}* in the\n| *responseDetails* field.\n\nLimitations\n-----------\n\nThe following gRPC features are not yet supported in API Gateway:\n\n- Payload compression\n- Any IDL other than protocol buffers\n\nAPI Gateway only supports Cloud Run\ngRPC services at this time.\n\nWhat's next\n-----------\n\n- Explore samples. The `getting-started-grpc` sample is available on GitHub in the following languages:\n - [Java](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/endpoints/getting-started-grpc)\n - [Python](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/endpoints/getting-started-grpc)\n - [Ruby](https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/endpoints/getting-started-grpc)\n - [Go](https://github.com/GoogleCloudPlatform/golang-samples/tree/master/endpoints/getting-started-grpc)\n - [Node.js](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/endpoints/getting-started-grpc)\n- The Bookstore sample is available in the following languages:\n - [Python](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/endpoints/bookstore-grpc)\n - [Java](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/endpoints)"]]