官术网_书友最值得收藏!

gRPC

The gRPC has a more complete proposal than MsgPack because it is composed of the data serializer Protobuf, as a layer between communication services making use of RPC.

For serialization, create a .proto file with the information about what will be serialized for RPC communication following a client/server model if needed.

The following code can be seen as an example of a .protocol file, that was extracted from the official site tool:

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; 
   } 

The file .proto has a specific form of writing. The positive aspect of a file like this is that the signing of the communication layer is normalized because, at some level, the file created as the serialization template and creating clients/servers ends up serving as the  documentation of endpoints.

After the file is created, to create the communication part you need only run a command line. The following example creates the client/server in Python:

    $ python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/file_name.proto  

The command may seem a little intimidating at first but is enough to generate a client and server RPC of communication. The gRPC has evolved a lot and received strong investment.

With regards to the compatibility, gRPC does not meet the same requirements that MsgPack does, but has compatibility with the most commonly used languages in the market.

主站蜘蛛池模板: 岱山县| 历史| 昂仁县| 朝阳市| 太原市| 防城港市| 义马市| 青龙| 承德市| 凤阳县| 上蔡县| 榕江县| 罗江县| 那曲县| 师宗县| 满洲里市| 寿光市| 三明市| 乐清市| 霍山县| 扶风县| 上栗县| 元朗区| 河源市| 西藏| 龙井市| 蓬安县| 玛纳斯县| 凌源市| 益阳市| 霸州市| 太和县| 南投市| 长海县| 比如县| 自贡市| 临朐县| 曲水县| 江城| 卓尼县| 永泰县|