Go RPC学习

RPC(remote procedure call)远程过程调用

gRPC

谷歌的rpc框架,它的idlProtocol Buffers

idl(interface definition language 接口描述语言)

四种服务类型

  1. Unary
  2. client-side streaming
  3. server-side streaming
  4. bidirectional-streaming

ProtoBuf

​​​​​​Protocol Buffers  |  Google Developers

protobuf详解 - 知乎 (zhihu.com)

/*
描述服务
1、GetFeature:输入一个Point,返回这个点的Fearture
2、ListFearchs,(输入为一个Rectangle,输出流这个区域内所有的Fearture)
3、RecordRoute,(输入流位每个时间点的Point,返回一个RouteSammary)
4、Recommend,(输入流RecommendationRequest,输出流Fearture)
 */

syntax ="proto3";
//option go_package
package route;

message Point{
  int32 latitude = 1;
  int32 longitude = 2;
}

message Rectangle{
  Point lo = 1;
  Point hi = 2;
}

message Fearture{
  string name = 1;
  Point location = 2;
}

message RouteSammary{
  int32 pointCount =1;
  int32 distance =2;
  int32 elapsedTime = 3;
}

enum RecommendationMode{
  GetFarthest = 0;
  GetNearest = 1;
}

message RecommendationRequest{
  RecommendationMode mode =1;
  Point point =2;
}

service RouteService{
  //unary
  rpc GetFeature(Point) returns (Fearture){}
  //server side streaming
  rpc ListFeature(Rectan

你可能感兴趣的:(GO,rpc,golang,网络协议)