https://github.com/fullstorydev/grpcurl
grpcurl is a command-line interface (CLI) tool designed for interacting with gRPC (Remote Procedure Call) servers, serving as the equivalent of cURL for HTTP-based APIs. With grpcurl, users can easily send requests to gRPC servers, inspect responses, and debug gRPC-based services directly from the command line. This tool simplifies the process of working with gRPC APIs, allowing developers to test endpoints, diagnose issues, and explore service capabilities with ease.
#列出有哪些服务
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 list
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
pb.usermanagerService
pb.randmanagerService
#列出某个服务的方法
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 list pb.randmanagerService
pb.randmanagerService.GenerateRandomKey
pb.randmanagerService.GetRandomNumber
#查看某个方法的描述
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 describe pb.randmanagerService.GetRandomNumber
pb.randmanagerService.GetRandomNumber is a method:
rpc GetRandomNumber ( .pb.GetRandomNumberRequest ) returns ( .pb.GetRandomNumberResponse );
#查看某个方法的参数描述
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 describe pb.GetRandomNumberRequest
pb.GetRandomNumberRequest is a message:
message GetRandomNumberRequest {
int32 num = 1;
int32 length = 2;
}
#查看某个方法的返回值描述
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 describe pb.GetRandomNumberResponse
pb.GetRandomNumberResponse is a message:
message GetRandomNumberResponse {
int32 code = 1;
string msg = 2;
.pb.GetRandomNumberData data = 3;
}
[work@localhost ~]$ grpcurl -plaintext 192.168.10.202:8090 describe pb.GetRandomNumberData
pb.GetRandomNumberData is a message:
message GetRandomNumberData {
repeated string randoms = 1;
}
#请求某个方法
[work@localhost ~]$ grpcurl -d '{"num":2,"length":8}' -plaintext 192.168.10.202:8090 pb.randmanagerService.GetRandomNumber
{
"msg": "ok",
"data": {
"randoms": [
"23e9c800",
"18db8480"
]
}
}
#使用文件请求某个方法
[work@localhost ~]$ cat params.json | grpcurl -d @ -plaintext 192.168.10.202:8090 pb.randmanagerService.GetRandomNumber
{
"msg": "ok",
"data": {
"randoms": [
"23e9c800",
"18db8480"
]
}
}
#测试某个方法的耗时
[work@localhost ~]$ date; grpcurl -connect-timeout 3600 -keepalive-time 3600 -max-time 3600 -d '{"num":2,"length":8}' -plaintext 192.168.10.202:8090 pb.randmanagerService.GetRandomNumber; date
2025年 04月 27日 星期日 13:14:52 CST
ERROR:
Code: DeadlineExceeded
Message: context deadline exceeded
2025年 04月 27日 星期日 13:16:32 CST
--end--