This is a creation in Article, where the information may have evolved or changed.
GRPC is a high-performance, general-purpose, open-source RPC framework developed by Google primarily for mobile applications and based on the HTTP/2 protocol standards, developed based on the Protobuf (protocolbuffers) serialization protocol, and supports many development languages. GRPC provides an easy way to precisely define services and automatically generate a highly reliable client function library for iOS, Android, and background support services. Clients take advantage of advanced streaming and linking capabilities to help conserve bandwidth, reduce the number of TCP links, conserve CPU usage, and battery life.
1 Installation
go get Google.golang.org/grpc
2 Create Helloworld.proto
syntax = "Proto3";
option java_package = "Io.grpc.examples";
package HelloWorld;
//the Greeting service definition.
service Greeter {
//sends a Greeting
rpc SayHello (hellorequest) returns (Helloreply) {}
}
The request message containing the user ' s name.
Message Hellorequest {
string name = 1;
}
The response message containing the greetings
Message helloreply {
String message = 1;
}
3. Installing PROTOC
Download the Protoc tool:
Https://github.com/google/protobuf, has the source code and compiles well, chooses by oneself
To install the Go plugin:
Go get-a github.com/golang/protobuf/protoc-gen-go
4. Generate the Golang file
Protoc-i././helloworld.proto--go_out=plugins=grpc:helloworld
5. Obtain the Instance code:
$ go get-u github.com/grpc/grpc-common/go/greeter_client
$ go get-u github.com/grpc/grpc-common/go/greeter_server
6. Running
Service side:
$ Greeter_server &
Client:
$ greeter_client
Interested, can discuss together!!