当前位置:网站首页>Golang RPC (7): how to debug grpc service

Golang RPC (7): how to debug grpc service

2022-06-09 12:32:00 raoxiaoya

gRPC The default is protobuf Encoded is not clear text , secondly , Be similar to RESTFUL API, We also need curl and postman Such a debugging tool .gRPC There are similar tools , The corresponding difference is grpcurl and grpcui.

grpcurl- Command line tools

similar curl, It can be directly used to send a request to call a remote grpc service , Please see the official address grpcurl

install

You can also use go get install

go get -u github.com/fullstorydev/grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl

Use

Be careful grpcurl It's based on reflection , You need to add such a line of code before starting the service

s := grpc.NewServer()
reflection.Register(s)

1. Query service list

grpcurl -plaintext 127.0.0.1:50051 list
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter

2. Query the methods provided by the service

grpcurl -plaintext 127.0.0.1:50051 list helloworld.Greeter
helloworld.Greeter.SayHello

3. See a more detailed description

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. Get type information

grpcurl -plaintext 127.0.0.1:50051 describe helloworld.HelloReply

Output

helloworld.HelloReply is a message:
message HelloReply {
    
  string message = 1;
}

5. Call service method

grpcurl -plaintext -d '{"name":"rao"}' 127.0.0.1:50051 helloworld.Greeter/SayHello

Output

{
    
  "message": "Hello rao"
}

grpcui- Interface tools

To put it simply , Namely gRPC Medium postman, Can take you to fly , Official address grpcui

install

go get -u github.com/fullstorydev/grpcui
go install github.com/fullstorydev/grpcui/cmd/grpcui

 There is an error 
/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]
        
 perform 
go get github.com/fullstorydev/grpcui/cmd/[email protected]

Use

function web Interface , Appoint grpc The address of

grpcui -plaintext localhost:50051

gRPC Web UI available at http://127.0.0.1:1728/

Tips Web UI The address for http://127.0.0.1:1728/
Access the following interface
 Insert picture description here

Input parameters , Initiate request

 Insert picture description here

 Insert picture description here

原网站

版权声明
本文为[raoxiaoya]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091145427710.html