将 HTTP 转换为 gRPC
gRPC 是一个基于 HTTP/2 协议的开源高性能远程过程调用 (RPC) 框架。它使用 protocol buffers (protobuf) 作为接口描述语言 (IDL)。
本指南将向你展示如何使用 grpc-transcode 插件与 proto 对象 在 RESTful HTTP 请求和 gRPC 请求以及它们相应的响应之间进 行转换。

备注
Ingress Controller 目前不支持 proto 资源。
前置条件
- 安装 Docker。
- 安装 cURL 以向 APISIX 发送请求进行验证。
- 安装 gRPCurl 以向 gRPC 服务发送请求进行验证。
- 按照 快速入门教程 在 Docker 中启动一个新的 APISIX 实例。
部署示例 gRPC 服务器
启动一个 示例 gRPC 服务器 Docker 实例 quickstart-grpc-example,端口为 50051:
docker run -d \
--name quickstart-grpc-example \
--network=apisix-quickstart-net \
-p 50051:50051 \
api7/grpc-server-example:1.0.2
此示例 gRPC 服务器拥有多个服务,例如 echo.EchoService:
echo.proto
syntax = "proto3";
package echo;
service EchoService {
rpc Echo (EchoMsg) returns (EchoMsg);
}
message EchoMsg {
string msg = 1;
}
在此示例中,Echo 是 EchoService 中的一个方法,它接受 EchoMsg 类型的参数。