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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.27.58