通过 APISIX 代理 gRPC 连接,并使用 APISIX 的大部分特性管理你的 gRPC 服务。
service_protocol
: 这个 Route 的属性 service_protocol
必须设置为 grpc
uri
: 格式为 /service/method 如:/helloworld.Greeter/SayHello在指定 Route 中,代理 gRPC 服务接口:
service_protocol
必须设置为 grpc
;curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' { "methods": ["POST", "GET"], "uri": "/helloworld.Greeter/SayHello", "service_protocol": "grpc", "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:50051": 1 } } }'
访问上面配置的 Route:
grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto \ -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello { "message": "Hello apisix" }
这表示已成功代理。