grpc 入门(二)-- 服务接口类型
本节是继上一章节Hello world的进一步深入挖掘;
一、grpc服务接口类型
在godoc的网站上对grpc的端口类型进行了简单的介绍,总共有下面4种类型[1]:
gRPC lets you define four kinds of service method:
Unary RPCs where the client sends a single request to the server and gets a single response back, just like a normal function call.
rpc SayHello(HelloRequest) returns (HelloResponse){
}
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.
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse){
}
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.
rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse) {
}
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.
rpc BidiHello(stream HelloRequest) returns (stream HelloResponse){
}
We’ll look at the different types of RPC in more detail in the RPC life cycle section below.
上面是从官网摘抄过来的,简单的来讲客户端和服务发送数据有两种形式:Unary和Streaming。Unary (一元)一次只发送一个包; Streaming(流)一次可以发送多个包。两种方式组合一下就形成了4种类型:
| 服务端 | 客户端 | |
| 1 | Unary | Unary |
| 2 | Streaming | Streaming |
| 3 | Unary | Streaming |
| 4 | Streaming | Unary |
在上一篇Hello world文章里面的示例就是第一种类型接口,它最终声明了一个需要开发者去实习具体业务逻辑的接口:
// Server API for Greeter service
type GreeterServer interface {
// Sends a greeting
SayHello(context.Context, *HelloRequest) (*HelloReply, error)
}
开发者需要根据业务需求来考虑使用不同的grpc服务接口类型 。
参考网址
[1] https://grpc.io/docs/guides/concepts.html#service-definition
grpc 入门(二)-- 服务接口类型的更多相关文章
- Go GRPC 入门(二)
前言 最近较忙,其实准备一篇搞定的 中途有事,只能隔了一天再写 正文 pb.go 需要注意的是,在本个 demo 中,客户端与服务端都是 Golang,所以在客户端与服务端都公用一个 pb.go 模板 ...
- gRPC (1):入门及服务端创建和调用原理
1. RPC 入门 1.1 RPC 框架原理 RPC 框架的目标就是让远程服务调用更加简单.透明,RPC 框架负责屏蔽底层的传输方式(TCP 或者 UDP).序列化方式(XML/Json/ 二进制)和 ...
- 微服务架构攀登之路(三)之gRPC入门
一.gRPC入门 1. gRPC 简介 gRPC 由 google 开发,是一款语言中立.平台中立.开源的远程过程调用系统 gRPC 客户端和服务端可以在多种环境中运行和交互,例如用 java 写一个 ...
- 【原创】NIO框架入门(二):服务端基于MINA2的UDP双向通信Demo演示
前言 NIO框架的流行,使得开发大并发.高性能的互联网服务端成为可能.这其中最流行的无非就是MINA和Netty了,MINA目前的主要版本是MINA2.而Netty的主要版本是Netty3和Netty ...
- 微服务(入门二):netcore通过consul注册服务
基础准备 1.创建asp.net core Web 应用程序选择Api 2.appsettings.json 配置consul服务器地址,以及本机ip和端口号信息 { "Logging&qu ...
- .net core grpc consul 实现服务注册 服务发现 负载均衡(二)
在上一篇 .net core grpc 实现通信(一) 中,我们实现的grpc通信在.net core中的可行性,但要在微服务中真正使用,还缺少 服务注册,服务发现及负载均衡等,本篇我们将在 .net ...
- go微服务系列(四) - gRPC入门
1. 前言 2. gRPC与Protobuf简介 3. 安装 4. 中间文件演示 4.1 编写中间文件 4.2 运行protoc命令编译成go中间文件 5. 创建gRPC服务端 5.1 新建Produ ...
- 微服务入门二:SpringCloud(版本Hoxton SR6)
一.什么是SpringCloud 1.官方定义 1)官方定义:springcloud为开发人员提供了在分布式系统中快速构建一些通用模式的工具(例如配置管理.服务发现.断路器.智能路由.微代理.控制总线 ...
- C#二次开发BIMFACE系列61 File Management文件管理服务接口二次开发及实战详解
系列目录 [已更新最新开发文章,点击查看详细] 在我的博客<C#二次开发BIMFACE系列61 File Management文件管理服务接口二次开发及实战详解>最后列出了 Fil ...
随机推荐
- 浅析VS2010反汇编
第一篇 1. 怎样进行反汇编 在调试的环境下,我们能够很方便地通过反汇编窗体查看程序生成的反汇编信息. 例如以下图所看到的. 记得中断程序的运行,不然看不到反汇编的指令 看一个简单的程序及其生成的汇编 ...
- 021.1 IO流——File类
########################################IO流: IO:用于处理设备上的数据的技术.设备:内存,硬盘,光盘 流:系统资源,Windows系统本身就可 ...
- 019.2 map集合类
Map<k,v>Map:双列集合,一次存一对,键值对,类似于python的字典.共性功能:1.添加 v put(key,value) //返回key的旧值 putAll ...
- SVN There are unfinished transactions detected
在ECLIPSE中报这个错,不能提交和更新代码和clean up 解决办法:关闭ECLIPSE,使用工具对SVN执行 clean up. 重新启动ECLIPSE,解决冲突文件,可以正常使用SVN
- IOS Singleton(单例)
Singleton.h // .h #define singleton_interface(class) + (instancetype)shared##class; // .m #define si ...
- struts文件上传——文件过大时错误提示的配置问题说明
开始只在struts.xml文件中加入以下配置 <constant name="struts.multipart.maxSize" value="10000&quo ...
- POJ 2407 Relatives 欧拉函数题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- 【[SCOI2009]迷路】
大水题一遍 过掉比较繁琐的拆点还是非常开心的 发现每一条边的边权可能不是\(1\),但是边权的范围非常小,同时点数也非常小,只有\(n<=10\),所以我们可以将一个点拆成九个点,之后随便一连边 ...
- 【JavaScript】富文本编辑器
这是js写的富文本编辑器,还存在一些bug,但基本功能已经实现,通过这个练习,巩固了js富文本编辑方面的知识,里面包含颜色选择器.全屏.表情.上传图片等功能,每个功能实际对应的就是一个小插件啦 部分程 ...
- 2、Dubbo-核心概念
dubbo核心概念 2.1).简介 Apache Dubbo (incubating) |ˈdʌbəʊ| 是一款高性能.轻量级的开源Java RPC框架, 它提供了三大核心能力:面向接口的远程方法调用 ...