Go 如何在CloudRun上反射gRPC服务的grpcurl列表?
下面这个例子: 谷歌云运行中的gRPC 我在CloudRun上部署了一个带有反射的gRPC服务 使用grpcurl进行测试: GRPC服务器反射协议 现在我想按照这些说明使用反射Go 如何在CloudRun上反射gRPC服务的grpcurl列表?,go,grpc,google-cloud-run,Go,Grpc,Google Cloud Run,下面这个例子: 谷歌云运行中的gRPC 我在CloudRun上部署了一个带有反射的gRPC服务 使用grpcurl进行测试: GRPC服务器反射协议 现在我想按照这些说明使用反射 --- a/examples/helloworld/greeter_server/main.go +++ b/examples/helloworld/greeter_server/main.go @@ -40,6 +40,7 @@ import ( "google.golang.org/
--- a/examples/helloworld/greeter_server/main.go
+++ b/examples/helloworld/greeter_server/main.go
@@ -40,6 +40,7 @@ import (
"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
+ "google.golang.org/grpc/reflection"
)
const (
@@ -61,6 +62,8 @@ func main() {
}
s := grpc.NewServer()
pb.RegisterGreeterService(s, &pb.GreeterService{SayHello: sayHello})
+ // Register reflection service on gRPC server.
+ reflection.Register(s)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
您尝试的内容:
本地测试。请注意:
grpcurl-纯文本表示不是TLS。Ommiting-明文表示TLS
工作内容:
############################
# local testing
############################
request list:
grpcurl -plaintext localhost:8080 list
result:
Calculator
grpc.reflection.v1alpha.ServerReflection
request ADD function:
grpcurl -plaintext \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
localhost:8080 \
Calculator.Calculate
result:
{
"result": 5
}
############################
request:
grpcurl \
-proto protos/calculator.proto \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
result:
{
"result": 5
}
您尝试的内容:
GCP CloudRun测试。请注意:
grpcurl-纯文本表示不是TLS。Ommiting-明文表示TLS
工作内容:
############################
# local testing
############################
request list:
grpcurl -plaintext localhost:8080 list
result:
Calculator
grpc.reflection.v1alpha.ServerReflection
request ADD function:
grpcurl -plaintext \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
localhost:8080 \
Calculator.Calculate
result:
{
"result": 5
}
############################
request:
grpcurl \
-proto protos/calculator.proto \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
result:
{
"result": 5
}
什么不起作用:
我想使用省略的反射:
-proto protos/calculator.proto \
-plaintext
我想使用省略的TLS:
-proto protos/calculator.proto \
-plaintext
请求:
grpcurl \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
答复:
超时
底线。本地测试表明反射工作正常。
部署到CloudRun时,它无法工作
我想是因为它需要双向流:
gRPC反射需要双向流,因此在部署时请确保选中启用HTTP/2选项(--use-http2)。这将启用BIDI流
另外,请确保使用:443端口,并在需要时通过添加身份验证元数据(请参阅服务到服务身份验证文档)向服务器进行身份验证。您认为它为什么不起作用?你犯了什么错误?您希望grpcurl如何进行身份验证(您需要提供授权头/元数据)。请添加更多详细信息。grpcurl需要指定端口号:如下所示:grpcurl localhost:8787列表。显然,443不能是端口号。我的请求是:grpcurl-明文grpc云运行示例服务器xxx.a.run.app:443列表未能拨打目标主机“grpc云运行示例服务器xxx.a.run.app:443”:超出上下文截止日期:443正确。但是您需要让grpcurl使用TLS。Cloud Run强制TLS,如果您尝试以明文形式与TLS端点对话,您将得到该错误。根据一般经验,请编辑您的问题,列出“您尝试了什么”、“哪些有效”和“哪些无效”。我修改了我的帖子,请看。我看了,得到了信息:使用
gcloudalpha
设置--Use-http2
云运行(完全管理)。我的项目是否应该为http2启用?该功能正在预览中,请确保更新gcloud,并使用gcloud beta
。gcloud beta--use-http2完成了任务!