当前位置:网站首页>Golang-RPC(七):如何调试gRPC服务
Golang-RPC(七):如何调试gRPC服务
2022-06-09 11:45:00 【raoxiaoya】
gRPC默认是 protobuf 编码的并不是明文的,其次,类似于RESTFUL API,我们也需要 curl 和 postman 这样的调试工具。gRPC也有类似的工具,对应的分别是grpcurl和grpcui。
grpcurl-命令行工具
类似 curl,可以直接用来发送请求调用远程的 grpc 服务,官方地址请看 grpcurl
安装
也可以使用go get安装
go get -u github.com/fullstorydev/grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl
使用
注意grpcurl是基于反射,需要在启动服务前添加这样一行代码
s := grpc.NewServer()
reflection.Register(s)
1.查询服务列表
grpcurl -plaintext 127.0.0.1:50051 list
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter
2.查询服务提供的方法
grpcurl -plaintext 127.0.0.1:50051 list helloworld.Greeter
helloworld.Greeter.SayHello
3.查看更详细的描述
grpcurl -plaintext 127.0.0.1:50051 describe helloworld.Greeter
helloworld.Greeter is a service:
service Greeter {
rpc SayHello ( .helloworld.HelloRequest ) returns ( .helloworld.HelloReply );
}
4.获取类型信息
grpcurl -plaintext 127.0.0.1:50051 describe helloworld.HelloReply
输出
helloworld.HelloReply is a message:
message HelloReply {
string message = 1;
}
5.调用服务方法
grpcurl -plaintext -d '{"name":"rao"}' 127.0.0.1:50051 helloworld.Greeter/SayHello
输出
{
"message": "Hello rao"
}
grpcui-界面工具
简单的说,就是gRPC中的postman,能带你飞起来那种,官方地址 grpcui
安装
go get -u github.com/fullstorydev/grpcui
go install github.com/fullstorydev/grpcui/cmd/grpcui
出现报错
/root/gowork/pkg/mod/github.com/fullstorydev/[email protected]/cmd/grpcui/grpcui.go:31:2: missing go.sum entry for module providing package github.com/pkg/browser (imported by github.com/fullstorydev/grpcui/cmd/grpcui); to add:
go get github.com/fullstorydev/grpcui/cmd/[email protected]
/root/gowork/pkg/mod/github.com/fullstorydev/[email protected]/cmd/grpcui/grpcui.go:32:2: missing go.sum entry for module providing package golang.org/x/crypto/ssh/terminal (imported by github.com/fullstorydev/grpcui/cmd/grpcui); to add:
go get github.com/fullstorydev/grpcui/cmd/[email protected]
执行
go get github.com/fullstorydev/grpcui/cmd/[email protected]
使用
运行web界面,指定grpc的地址
grpcui -plaintext localhost:50051
gRPC Web UI available at http://127.0.0.1:1728/
提示Web UI的地址为 http://127.0.0.1:1728/
访问出来以下界面
输入参数,发起请求


边栏推荐
- 01 | context: why is Zhongtai so popular?
- 2.<tag-回溯和组合及其剪枝>lt.216.组合总数 |||
- Origin: unable to import data, solution to sticking data
- No remote desktop license server can provide licenses
- [reprint] understand G1 garbage collector
- 给 Web3 项目的智能合约安全指南
- [data center stage] 00 opening words data center stage, is it a trap? Or the golden key?
- Is the futures account opening cloud reliable and safe??
- ThreadPoolExecutor 从精通到入门
- 4. < tag backtracking, combination and pruning > lt.39 Combined sum + lt.40 Combined sum II DBC
猜你喜欢

What are the deadlock troubleshooting tools?

Relay alphafold! Star pharmaceutical science and technology released a new era of tbind opening molecular protein complex structure prediction

『忘了再学』Shell基础 — 28、AWK中条件表达式说明
![[untitled]](/img/c1/35479e8bd3832e3b6d9452768c4f13.png)
[untitled]

给 Web3 项目的智能合约安全指南

SIGIR 2022 | CMI: micro video recommendation combining comparative learning and multi interest mining

13.<tag-二叉树和BST基础>lt.450. 删除二叉搜索树中的节点 dbc

软件项目管理考点整理(Software Project Management)

flutter 文件操作

Fairness through awareness
随机推荐
科研論文寫作
go语言time.Format的坑
leetcode 1332. Remove Palindromic Subsequences(删掉回文子串)
09 | the fourth step: the construction and delivery of the middle office
【转载】搞懂G1垃圾收集器
04 | everything must be done in advance: four issues that must be clearly considered before the construction of China Taiwan Relations
flutter 文件操作
Do you dare to deliver your microservices independently?
2. < tag backtracking, combination and pruning > lt.216 Total number of combinations|||
MySQL SQL statement optimization
Software project management
6. < tag backtracking and cutting problems > lt.131 Split palindrome string
柴云鹏:创新能力的培养至关重要|OceanBase 数据库大赛访谈
MySQL optimistic lock, pessimistic lock and multi granularity lock
JUC-实现Future
Gson, fastjason, Jackson serialization differences
软件项目管理考点整理(Software Project Management)
Xiemengjun: China's go language leader in the fifth year of entrepreneurship
4.<tag-回溯和组合及其剪枝>lt.39.组合总和 + lt.40. 组合总和 II dbc
[data center stage] 00 opening words data center stage, is it a trap? Or the golden key?