grpcurl 安装
macos
brew install grpcurl
linux
sudo apt-get install -y grpc
sudo apt-get install -y grpc-doc
列出服务
~ $ grpcurl -plaintext localhost:9770 list
api.mytool.Master
grpc.channelz.v1.Channelz
grpc.health.v1.Health
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
kratos.api.Metadata
查看服务的接口
~ $ grpcurl -plaintext localhost:9770 list api.mytool.Master
api.mytool.Master.Action
api.mytool.Master.CreateTask
api.mytool.Master.DeployTask
api.mytool.Master.Ping
api.mytool.Master.WorkerServer
查看接口定义
~ $ grpcurl -plaintext localhost:9770 describe api.mytool.Master.DeployTask
api.mytool.Master.DeployTask is a method:
rpc DeployTask ( .api.mytool.DeployTaskRequest ) returns ( .api.mytool.DeployTaskReply ) {
option (.google.api.http) = { post: "/master/task/deploy", body: "*" };
}
查看接口参数定义
~ $ grpcurl -plaintext localhost:9770 describe api.mytool.DeployTaskRequest
api.mytool.DeployTaskRequest is a message:
message DeployTaskRequest {
string host = 1;
int64 task_id = 2;
}
请求服务接口
~ $ grpcurl -plaintext -d '{"host":"all", "task_id":10}' localhost:9770 api.mytool.Master.DeployTask
{
"header": {
"reason": "SUCCESS",
"message": "响应正常"
},
"data": {
"results": [
{
"host": "localhost:9870",
"sn": "worker1",
"status": "success",
"message": "Success",
"reason": "SUCCESS"
}
]
}
}