宝藏好物gRPCurl
gRPCurl簡介
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特性
gRPCurl是由gRPC社區創建的命令行工具,功能包括:
?調用gRPC服務,包括流式服務?使用gRPC反射進行服務發現?列出并描述 gRPC服務?支持調用安全(TLS)或者不安全(plain-text)的gRPC服務
ASP.NET Core設置grpc反射
?添加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();}}); }服務發現、服務調用
grpcurl list/describe 可以列出gRPC服務端反射的protobuf
1.?grpcurl localhost:5001 list
greet.Greeter grpc.reflection.v1alpha.ServerReflection
2.?grpcurl localhost:5001 describe
?grpc -d ( Data for request contents) 傳參調用gRPC方法
3.?grpcurl -d {"name":"World"} localhost:5001 greet.Greeter/SayHello
{"message": "Hello World" }gRPCui
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窗口:
輸入Request Header、Request Data,自行倒騰。
就是這么神奇!
以上是利用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
性感豹紋
?HTTP1.1 Keep-Alive到底算不算長連接?
?Hostonly cookie是什么鬼?
?前端鏡像打包這么慢,你該反省一下dockerfile的姿勢了
?SignalR 開發到生產部署閉坑指南
?難纏的布隆過濾器,這次終于通透了
點個在看你最好看
僅代表此刻認知,文章永久更新地址,請移步原文!!
總結
以上是生活随笔為你收集整理的宝藏好物gRPCurl的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OAuth 2.1 的进化之路
- 下一篇: 从 ThreadLocal 到 Asyn