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

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.

主站蜘蛛池模板: 个旧市| 应城市| 七台河市| 策勒县| 沙湾县| 固始县| 汉寿县| 铜川市| 卢龙县| 庆安县| 淮北市| 遂宁市| 普陀区| 玛沁县| 江孜县| 屯留县| 和龙市| 项城市| 凌海市| 文登市| 昌邑市| 阿瓦提县| 高唐县| 安达市| 新宾| 天柱县| 博罗县| 泰和县| 定远县| 涟水县| 额尔古纳市| 万安县| 上饶市| 泗阳县| 文水县| 都匀市| 瑞金市| 娄烦县| 昌都县| 东乌| 肥城市|