grpcurl使用

2022-08-02 19:04:17 浏览数 (1)

1,grpcurl 127.0.0.1:57904 list

Failed to dial target host "127.0.0.1:57904": tls: first record does not look like a TLS handshake

原因grpc默认是https

2,grpcurl -plaintext 127.0.0.1:57904 list

grpc.health.v1.Health

grpc.reflection.v1alpha.ServerReflection

xxx.svc.xx.XXService

加-plaintext 走http 解决

3,grpcurl -plaintext 127.0.0.1:57904 list xxx.svc.xx.XXService

xxx.svc.xx.XXService.xxMethod

xxx.svc.xx.XXService.yyMethod

前提是服务端起了reflection

4,grpcurl -plaintext 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

ERROR:

Code: InvalidArgument

Message: xxx

缺少参数

5,grpcurl -plaintext 127.0.0.1:57904 describe xxx.svc.xx.XXService

e xxx.svc.xx.XXService is a service:

service XXService {

rpc yyMethod ( .google.protobuf.Empty ) returns ( .google.protobuf.Empty );

6.grpcurl -plaintext 127.0.0.1:57904 describe xxx.svc.xx.XXService.yyMethod

xxx.svc.xx.XXService.yyMethod is a method:

rpc yyMethod ( .xxx.svc.xx.XXService.yyMethodRequest ) returns ( .xxx.svc.xx.XXService.yyMethodResponse );

7.grpcurl -plaintext 127.0.0.1:57904 describe .xxx.svc.xx.yyMethodRequest

.xxx.svc.xx.yyMethodRequest is a message:

message yyMethodRequest {

string xxx = 1;

int64 yyy = 2;

}

8.grpcurl -plaintext 127.0.0.1:57904 -d '{"xxx":"12133","yyy":0}' xxx.svc.xx.XXService/yyMethod

Too many arguments.

原因:请求参数位置不对

9.grpcurl -plaintext -d '{"xxx":"12133","yyy":0}' 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

ERROR:

Code: PermissionDenied

原因 缺少meta参数(header)

10.grpcurl -plaintext -d '{"xxx":"12133","yyy":0}' -H '"Xx":1234' 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

Error invoking method "xxx.svc.xx.XXService/yyMethod": rpc error: code = Internal desc = failed to query for service descriptor "xxx.svc.xx.XXService/yyMethod": stream terminated by RST_STREAM with error code: PROTOCOL_ERROR

原因:没有指定proto 文件

11.grpcurl -plaintext -d '{"xxx":"12133","yyy":0}' -H '"Xx":1234' -proto "~/go/protos/xxx.proto" 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

Failed to process proto source files.: could not parse given files: %!v(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)

原因:没有指定依赖文件的目录

12. grpcurl -plaintext -d '{"xxx":"12133","yyy":0}' -H '"Xx":1234' -import-path "/go/protos/" -proto "/go/protos/xxx.proto" 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

ERROR:

Code: Internal

Message: stream terminated by RST_STREAM with error code: PROTOCOL_ERROR

原因:header 错误,原因header 里多了“

13.grpcurl -plaintext -emit-defaults 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

ERROR:

Code: InvalidArgument

Message: xxx or yyy is required

14.grpcurl -plaintext -d '{"xxx":"12133","yyy":0}' -H 'Xx:1234' -import-path "/go/protos/" -proto "/go/protos/xxx.proto" 127.0.0.1:57904 xxx.svc.xx.XXService/yyMethod

问题解决

0 人点赞