gRPCurl简介
https://img-blog.csdnimg.cn/img_convert/970e8d494de6d083773ec24f11fdeeb0.png" alt="970e8d494de6d083773ec24f11fdeeb0.png" />
gRPCurl[1]是一个与gRPC服务器交互的命令行工具,可认为是gRPC的curl
工具。
gRPCurl用于从命令行调用gRPC服务器支持的RPC方法,gRPC使用二进制编码(protobuf), 不能利用常规的curl工具(早期的curl版本还不支持HTTP/2)。
1. gRPCurl工具接受json编码的消息(对人类和脚本更友好), 工具底层会转化为protobuf与服务器交互。2.gRPCurl 必须了解服务的Protobuf协议(服务的schema),才能调用它们, gRPCurl通过三种方式之一实现此目的
• gRPC服务器添加gRPC反射• 直接读取proto源文件• 加载编译后的protoset文件 (包含已被编码的proto描述文件)
gRPCurl特性
https://img-blog.csdnimg.cn/img_convert/8d211cea929f57009b972f9a621eec35.png" alt="8d211cea929f57009b972f9a621eec35.png" />
gRPCurl是由gRPC社区创建的命令行工具,功能包括:
•调用gRPC服务,包括流式服务•使用gRPC反射进行服务发现•列出并描述 gRPC服务•支持调用安全(TLS)或者不安全(plain-text)的gRPC服务
ASP.NET Core设置grpc反射
https://img-blog.csdnimg.cn/img_convert/26fd4eda4d7eeb73d73c11c53a9a9abf.png" alt="26fd4eda4d7eeb73d73c11c53a9a9abf.png" />
•添加Grpc.AspNetCore.Server.Reflection包引用•Startup.cs注册反射
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddGrpcReflection();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
if (env.IsDevelopment())
{
endpoints.MapGrpcReflectionService();
}
});
}
服务发现、服务调用
https://img-blog.csdnimg.cn/img_convert/5dff44546446978d11432e8fdc013797.png" alt="5dff44546446978d11432e8fdc013797.png" />
grpcurl list/describe 可以列出gRPC服务端反射的protobuf
1. grpcurl localhost:5001 list
greet.Greeter
grpc.reflection.v1alpha.ServerReflection
2. grpcurl localhost:5001 describe
greet.Greeter is a service:
service Greeter {
rpc SayHello ( .greet.HelloRequest ) returns ( .greet.HelloReply );
}
grpc.reflection.v1alpha.ServerReflection is a service:
service ServerReflection {
rpc ServerReflectionInfo ( stream .grpc.reflection.v1alpha.ServerReflectionRequest ) returns ( stream .grpc.reflection.v1alpha.ServerReflectionResponse );
}
grpc -d ( Data for request contents) 传参调用gRPC方法
3. grpcurl -d {"name":"World"} localhost:5001 greet.Greeter/SayHello
{
"message": "Hello World"
}
gRPCui
https://img-blog.csdnimg.cn/img_convert/5b9c985b84ac66894368b45a219d2d1e.png" alt="5b9c985b84ac66894368b45a219d2d1e.png" />
gRPCui[2] 是 gRPC 的交互式 Web UI,基于gRPCurl,并提供一个GUI来发现和测试 gRPC 服务,类似于 Postman 或 Swagger UI 等 HTTP 工具。
•安装:go install github.com/fullstorydev/grpcui/cmd/grpcui@latest•使用:grpcui localhost:5001
会立刻打开类Swagger窗口:
https://img-blog.csdnimg.cn/img_convert/dab81143a3c27a5de824fdca87d834fa.png" alt="dab81143a3c27a5de824fdca87d834fa.png" />输入Request Header、Request Data,自行倒腾。
https://img-blog.csdnimg.cn/img_convert/4234b308604920dcfc1926c3548e6903.gif" alt="4234b308604920dcfc1926c3548e6903.gif" />就是这么神奇!
以上是利用gRPC服务反射获取protobuf的方式,gRPCurl还支持直接读取proto文件。
`grpcurl -import-path ../protos -proto greet.proto -d {\"name\":\"World\"} localhost:5001 greet.Greeter/SayHello`
引用链接
[1]
grpcur: https://github.com/fullstorydev/grpcurl[2]
gRPCui: https://github.com/fullstorydev/grpcui#installation
性感豹纹
https://img-blog.csdnimg.cn/img_convert/fbde1bc295a7c68fb26af4f104af82f3.gif" alt="fbde1bc295a7c68fb26af4f104af82f3.gif" /> HTTP1.1 Keep-Alive到底算不算长连接?
https://img-blog.csdnimg.cn/img_convert/1d77d12310e6b4f93f2b9b8cbd7775e1.gif" alt="1d77d12310e6b4f93f2b9b8cbd7775e1.gif" /> Hostonly cookie是什么鬼?
https://img-blog.csdnimg.cn/img_convert/247aac56c9652aa2c05a0f878932a8b5.gif" alt="247aac56c9652aa2c05a0f878932a8b5.gif" /> 前端镜像打包这么慢,你该反省一下dockerfile的姿势了
https://img-blog.csdnimg.cn/img_convert/f690009ceaab544d5332e307c8d10a79.gif" alt="f690009ceaab544d5332e307c8d10a79.gif" />
https://img-blog.csdnimg.cn/img_convert/dfd9ac09a023532730253e5e0413cc4d.gif" alt="dfd9ac09a023532730253e5e0413cc4d.gif" />
难缠的布隆过滤器,这次终于通透了
https://img-blog.csdnimg.cn/img_convert/1d91f6a656528a98d1af2ecd28e945b1.png" alt="1d91f6a656528a98d1af2ecd28e945b1.png" />
点个在看你最好看
https://img-blog.csdnimg.cn/img_convert/6395d1463e3cde51f9be509ed485bd93.png" alt="6395d1463e3cde51f9be509ed485bd93.png" />
仅代表此刻认知,文章永久更新地址,请移步原文!!