// 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;}
要将 gRPC 与 API Gateway 结合使用,您必须提供服务配置以及服务定义。这将配置服务的运行时行为,包括身份验证、服务中包含的 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"]],["最后更新时间 (UTC):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)"]]