Preface
ProtoBuf
is 061a321ff7f500?
ProtoBuf
is a set of interface description language (IDL), in layman's terms, it is a way of data expression, and it can also be called a data exchange format.
Our commonly used data formats are JSON
and XML
, why use ProtoBuf
? It is because of its fast transmission, why is it fast? You can find the information. Use .proto
file to describe the data structure to be serialized, and then write the .proto
file and use protoc
to easily compile into many computer language interface codes.
gRPC
is 061a321ff7f599?
gRPC
is the open source RPC
framework, which already supports mainstream computer languages. The interface can be defined ProtoBuf
, and data transmission ProtoBuf
Although the two are one family, they solve different problems separately and can be used together or separately.
Look at the gRPC
the HelloWorld of proto
how files are defined?
helloworld.proto
syntax = "proto3";
package helloworld;
option go_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;
}
service
Greeter and rpc
SayHello methods are defined in the file.
Entry: string
name
Reference: string
message
These are too simple, can you describe other information?
Little thinking
- Can the defined
rpc
also support the call ofHTTP
For example, the SayHello method supports both gRPC calls and HTTP calls. At the same time, it also supportsprotoc
generate code and also generatesSwagger
interface documents. - Can the defined input parameters support parameter verification? For example: the length of name cannot be greater than 20 characters.
- Can the defined
service
Greeter service support interceptors? For example: all methods under this service require login token verification. rpc
defined 061a321ff7f824 SayHello method support interceptors? For example: The current method supports whether to enable and disable logging.
summary
The above problems have not been completely solved, and learning gRPC feels a bit difficult...
Do you have any learning resources that you can recommend? Currently looking at grpc-gateway .
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。