本文介绍一些主要的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 异步

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

grpc:gRPC Concepts的更多相关文章

  1. 带入gRPC:gRPC Streaming, Client and Server

    带入gRPC:gRPC Streaming, Client and Server 原文地址:带入gRPC:gRPC Streaming, Client and Server 前言 本章节将介绍 gRP ...

  2. 带入gRPC:gRPC Deadlines

    带入gRPC:gRPC Deadlines 原文地址:带入gRPC:gRPC Deadlines项目地址:https://github.com/EDDYCJY/go... 前言 在前面的章节中,已经介 ...

  3. gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架

    gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架 gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架 Google Guava官方教程(中文版 ...

  4. 基于HTTP/2和protobuf的RPC框架:GRPC

    谷歌发布的首款基于HTTP/2和protobuf的RPC框架:GRPC Google 刚刚开源了grpc,  一个基于HTTP2 和 Protobuf 的高性能.开源.通用的RPC框架.Protobu ...

  5. grpc-gateway:grpc对外提供http服务的解决方案

    我所在公司的项目是采用基于Restful的微服务架构,随着微服务之间的沟通越来越频繁,就希望可以做成用rpc来做内部的通讯,对外依然用Restful.于是就想到了google的grpc. 使用grpc ...

  6. grpc-gateway:grpc转换为http协议对外提供服务

    我所在公司的项目是采用基于Restful的微服务架构,随着微服务之间的沟通越来越频繁,就希望可以做成用rpc来做内部的通讯,对外依然用Restful.于是就想到了google的grpc. 使用grpc ...

  7. 带入gRPC:对 RPC 方法做自定义认证

    带入gRPC:对 RPC 方法做自定义认证 原文地址:带入gRPC:对 RPC 方法做自定义认证项目地址:https://github.com/EDDYCJY/go... 前言 在前面的章节中,我们介 ...

  8. 思考gRPC :为什么是HTTP/2

    Introducing gRPC Support with NGINX 1.13.10 - NGINX https://www.nginx.com/blog/nginx-1-13-10-grpc/ 思 ...

  9. 跟我一起学Go系列:gRPC 入门必备

    RPC 的定义这里就不再说,看文章的同学都是成熟的开发.gRPC 是 Google 开源的高性能跨语言的 RPC 方案,该框架的作者 Louis Ryan 阐述了设计这款框架的动机,有兴趣的同学可以看 ...

随机推荐

  1. 【VS开发】使用 NuGet 管理项目库

    NuGet 使用 NuGet 管理项目库 Phil Haack 无论多么努力,Microsoft 也没办法提供开发人员所需要的每一个库. 虽然 Microsoft 在全球的员工人数接近 90,000, ...

  2. java中易错点

    1.A instanceof  B{这是没有好好利用java多态的表现} java中的二元操作符,测试A对象是否是B类的实例: 返回值:boolean类型 2.“==”与 “equals”的区别: = ...

  3. Java Android 开发数字不足位数前面补0

    import java.text.DecimalFormat; public void changeColor(View view) { DecimalFormat decimalFormat = n ...

  4. BZOJ 1303 中位数图 题解

    题面 因为所求的是中位数,所以考虑改变原序列.把大于 b 的数全部变为 1,小于 b 的数变为 −1,等于 b 则为 0.问题就变为求存在几个包含 b的区间和为 0 . 根据乘法原理,我们枚举每一个l ...

  5. 搜索专题:Balloons

    搜索专题:Balloons 这道题一看与时间有关,第一想到的就是BFS,定义一个状态,包含每一个状态的剩余气球数,已经进行的时间和每一个志愿者上一次吹气球的时间: 每一次状态转换时,检查是否有没有使用 ...

  6. jmeter的三种参数化方法

    JMeter的三种参数化方式包括: 1.用户参数 2.函数助手 3.CSV Data Set Config 一.用户参数 位置:添加-前置处理器-用户参数 操作:可添加多个变量或者参数 二.函数助手 ...

  7. mybatis一对多关联关系映射

    mybatis一对多关联关系映射 一对多关联关系只需要在多的一方引入少的一方的主键作为外键即可.在实体类中就是反过来,在少的一方添加多的一方,声明一个List 属性名 作为少的一方的属性. 用户和订单 ...

  8. crm---本项目的权限控制模式

    一:url权限:  最底层的权限控制,,缺点在与没有预判的机制,造成客户体验下降.           前提: 为controller中的每一个方法(即资源)定义一个资源(Resource)名称,,该 ...

  9. vue中使用stylus编写css

    安装步骤 cnpm install stylus --save-dev cnpm install stylus-loader --save-dev 写法如下: <style lang=" ...

  10. Linux上安装JDK1.8,tomcat9,以及mysql8的步骤

    (该篇是在centos7上安装JDK1.8.0_201  tomcat9.0.16 和 mysql8.0.15) 一.安装JDK 方式一 1.首先,下载JDK(链接http://www.oracle. ...