本文介绍一些主要的gRPC概念。

服务定义

gRPC支持4种方法:

1、Unary RPCs where the client sends a single request to the server and gets a single response back, just like a normal function call.

入参和返回值是一个普通的protocol buffer message。示例:

message HelloRequest {
string greeting = 1;
} message HelloResponse {
string reply = 1;
} service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}

2、Server streaming RPCs where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. gRPC guarantees message ordering within an individual RPC call.

入参是一个普通的protocol buffer message,返回值是一个流式的message。示例:

service HelloService {
rpc SayHello (HelloRequest) returns (stream HelloResponse);
}

3、Client streaming RPCs where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them and return its response. Again gRPC guarantees message ordering within an individual RPC call.

入参是一个流式的message,返回值是一个普通的message。示例:

service HelloService {
rpc SayHello (stream HelloRequest) returns (HelloResponse);
}

4、Bidirectional streaming RPCs where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved.

入参和返回值都是流式的message。示例:

service HelloService {
rpc SayHello (stream HelloRequest) returns (stream HelloResponse);
}

同步 VS 异步

同步方法、异步方法都有,根据需要选用。

最新文章

  1. JS 获取浏览器和屏幕宽高信息
  2. wifi,网关相关标识的获取
  3. ENVI数据显示操作【Tools菜单操作1】
  4. 在Entity Framework 7中进行数据迁移
  5. Java如何获取系统cpu、内存、硬盘信息
  6. 如何用Pr完成作业~
  7. 快速排序QuickSort
  8. hdu1022 Train Problem I
  9. 动态创建dom元素
  10. 判断iPhone和iPad 判断设备版本
  11. C#中dynamic的正确用法【转】
  12. wemall app商城源码Android之Native(原生)支付模式一demo
  13. HandlerThread实现数字时钟
  14. RPC架构简单理解
  15. Linux - script练习
  16. nginx 学习(一)
  17. Java-IO:复制文件
  18. libgdx退出对话框
  19. 【HTML】input标签中alt属性和title属性的比较
  20. Android设计元素-操作栏

热门文章

  1. angular - ngFor, trackby
  2. start-all.sh启动HDFS,datanode没有启动
  3. MySql MediumBlob——MySql的Bolb四种类型
  4. numpy-排序
  5. 使用Jenkins结合Gogs和SonarQube对项目代码进行测试、部署、回滚,以及使用keepalived+haproxy调度至后端tomcat
  6. Elasticsearch入门教程(三):Elasticsearch索引&映射
  7. vue-cli3.0本地代理cookie跨域请求Nginx配置
  8. h5与app混合开发,jsbridge
  9. 利用ARouter实现组件间通信,解决子模块调用主模块问题
  10. Python 安装cx_Oracle模块折腾笔记