gsp*_*spq 6 go grpc google-cloud-run
按照这个例子:
\nGoogle Cloud Run 中的 gRPC
\nhttps://github.com/grpc-ecosystem/grpc-cloud-run-example/blob/master/golang/README.md
\n我已经在 CloudRun 上部署了带有反射的 gRPC 服务。
\n使用 grpcurl 进行测试:\n https://github.com/fullstorydev/grpcurl
\ngrpcurl \\\n-proto protos/calculator.proto \\\n-d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n${ENDPOINT}:443 \\\nCalculator.Calculate\nRun Code Online (Sandbox Code Playgroud)\nGRPC 服务器反射协议\n https://github.com/grpc/grpc/blob/master/doc/server-reflection.md
\n现在我想按照这些说明使用反射。
\n--- a/examples/helloworld/greeter_server/main.go\n+++ b/examples/helloworld/greeter_server/main.go\n@@ -40,6 +40,7 @@ import (\n "google.golang.org/grpc"\n pb "google.golang.org/grpc/examples/helloworld/helloworld"\n+ "google.golang.org/grpc/reflection"\n )\n\n const (\n@@ -61,6 +62,8 @@ func main() {\n }\n s := grpc.NewServer()\n pb.RegisterGreeterService(s, &pb.GreeterService{SayHello: sayHello})\n+ // Register reflection service on gRPC server.\n+ reflection.Register(s)\n if err := s.Serve(lis); err != nil {\n log.Fatalf("failed to serve: %v", err)\n }\nRun Code Online (Sandbox Code Playgroud)\n\n你尝试过什么:
\n本地测试。请注意:\ngrpcurl -plaintext 表示不是 TLS。省略 -plaintext 表示 TLS。
\n什么有效:
\n############################\n# local testing\n############################\nrequest list:\ngrpcurl -plaintext localhost:8080 list\n\nresult:\nCalculator\ngrpc.reflection.v1alpha.ServerReflection\n\nrequest ADD function:\ngrpcurl -plaintext \\\n -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n localhost:8080 \\\n Calculator.Calculate\n\nresult:\n{\n "result": 5\n}\n############################\nRun Code Online (Sandbox Code Playgroud)\n您尝试过的操作:\na GCP CloudRun 测试。请注意:\ngrpcurl -plaintext 表示不是 TLS。省略 -plaintext 表示 TLS。
\n什么有效:
\nrequest:\ngrpcurl \\\n -proto protos/calculator.proto \\\n -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n ${ENDPOINT}:443 \\\n Calculator.Calculate\n\nresult:\n{\n "result": 5\n}\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\x99 不起作用:\n我想使用反射,因此省略:
\n-proto protos/calculator.proto \\\nRun Code Online (Sandbox Code Playgroud)\n我想使用 TLS 所以省略:
\n-plaintext\nRun Code Online (Sandbox Code Playgroud)\n要求:
\ngrpcurl \\\n -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n ${ENDPOINT}:443 \\\n Calculator.Calculate\nRun Code Online (Sandbox Code Playgroud)\n回复:
\n暂停
\n底线。本地测试显示反射工作正常。\n部署到 CloudRun 时无法工作。
\n我想是因为它需要双向流:
\nhttps://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto
\nservice ServerReflection {\n // The reflection service is structured as a bidirectional stream, ensuring\n // all related requests go to a single server.\n rpc ServerReflectionInfo(stream ServerReflectionRequest)\n returns (stream ServerReflectionResponse);\n}\nRun Code Online (Sandbox Code Playgroud)\n
gRPC Reflection 需要双向流,因此请确保在部署时选中启用 HTTP/2 选项 (--use-http2)。这将启用双向流。
另请确保使用 :443 端口,并在需要时通过添加身份验证元数据对服务器进行身份验证(请参阅服务到服务身份验证文档)。
| 归档时间: |
|
| 查看次数: |
9492 次 |
| 最近记录: |