grpc stream c++ example

  • codes:

     https://github.com/kacakaca/Test/tree/master/grpc_examples
    
    • 可在ubuntu上成功执行(需要安装grpc),执行make后生成可执行文件serverclient。然后分别在不同的terminal运行./server./client
    • service定义的information.proto中
    • server的实现在server.cc中
    • client的实现在client.cc中
  • 实现了4种service

        rpc AddRecord (Person) returns (google.protobuf.Empty) {
          
          }
        rpc DeleteRecords (stream ReqName) returns (google.protobuf.Empty) {
          
          }
        rpc GetRecordsByAge (AgeRange) returns (stream Person) {
          
          }
        rpc GetRecordsByNames (stream ReqName) returns (stream Person) {
          
          }
    
    • AddRecord用于增加一条记录,名字需要唯一(Unary RPCs)
    • DeleteRecords用于删除多条记录,删除ReqName对应的记录(client streaming RPCs)
    • GetRecordsByAge用于获取在某段年龄范围的记录(server streaming RPCs)
    • GetRecordsByNames用于获取多条请求姓名的记录(bi-streaming RPCs)

猜你喜欢

转载自blog.csdn.net/iamanda/article/details/112539366
今日推荐