grpc容器和grpcurl使用验证
启动测试镜像
docker run -it -d --name grpc111 --net=host opcache/busybox:grpcv3
grpcurl 使用
在使用 grpcurl 时,需要通过 -cert 和 -key 参数设置公钥和私钥文件,表示链接启用了 TLS 协议的服务。
对于没有启用 TLS 协议的 gRPC 服务,通过 -plaintext 参数忽略 TLS 证书的验证过程。
如果是 Unix Socket 协议,则需要指定 -unix 参数。
查看服务列表:
grpcurl -plaintext 127.0.0.1:50051 list
输出:
grpc.reflection.v1alpha.ServerReflectionproto.Greeter
查看某个服务的方法列表:
grpcurl -plaintext 127.0.0.1:50051 list proto.Greeter
输出:
proto.Greeter.SayHello
查看方法定义:
grpcurl -plaintext 127.0.0.1:50051 describe proto.Greeter.SayHello
输出:
proto.Greeter.SayHello is a method:rpc SayHello ( .proto.HelloRequest ) returns ( .proto.HelloReply );
查看请求参数:
grpcurl -plaintext 127.0.0.1:50051 describe proto.HelloRequest
输出:
proto.HelloRequest is a message:message HelloRequest { string name = 1;
}
请求服务:
grpcurl -d '{"name": "zhangsan"}' -plaintext 127.0.0.1:50051 proto.Greeter.SayHello
输出:
{ "message": "hello"}
启动测试镜像
docker run -it -d --name grpc111 --net=host opcache/busybox:grpcv2
grpcurl -d '{"name": "zhangs323an"}' -plaintext 127.0.0.1:50051 helloworld.Greeter.SayHello
{
"message": "Hello zhangs323an"
}




请登录之后再进行评论