当前位置:网站首页>A tour of gRPC: 06 - gRPC client straming
A tour of gRPC: 06 - gRPC client straming
2022-08-02 18:15:00 【InfoQ】
在上一篇中,We tried using server straming 的调用形式,Ten were createdLaptopand sent a filter bar 件后,由serverReturns results matching the filter criteria multiple times,And the cross-language calling capability of this calling form is verified.在本篇 中,我们将尝试使用client straming 即 client Send content multiple times,而serverAfter receiving all the content,返回一次 响应.This time we will use itclient straming This calling form realizes the function of image transmission
go Client Straming call
1. 修改 laptop_sercice.proto Add three related to uploading picturesmessage 和一个 rpc 函数,运行make gen 生成代码

2. 在service 下新建image_store.go Implement an image store

3. 在laptop_server.go 下添加imageStore 内容,并在NewLaptopServer中新增一个参数

4. use allNewLaptopServer 和 store modify the location(test 和 main),Run the unit test once
5. 实现laptop_server中的 UploadImage

6. 重构、修改 client 包下的main 代码

7. 在server包下的main.go代码

8. Write a unit test to test

We create a new one in the root directory of the projecttmp文件夹,and store a file named images.jpeg的图片.接下来,启动server和clientAttempt to transfer.



The file was transferred correctly and successfully.观察server的log可以发现,如我们预期,The picture is sent split.我们可以计算一下 ,图片大小为6164,Divided during transmission6个1024k和1个20k
Java Client Straming
1. 复制 go client Straming 中的laptop_service.proto 运行 mvn clean complie on the generated generation code to update
2. 在 service 包下 创建一个ImageStore interface

3. 在 service 包下 创建ImageSotre 实体类

4. 在service 包下 创建 DiskImageStore实现上面的 ImageStore

5. 在LaptopService 下实现uploadImage

6. 修改 LaptopServer 中的 main Add image upload content

7. 运行Java 的server 再运行 golang 的client 可以看到 img file receivedgolangThe picture sent by the client
8. 修改LaptopClient 并添加Java 客户端内容

9. 修改 LaptopService Add a maximum upload limit

同上,我们运行测试一下


同样,The file was transferred correctly and successfully.观察server 的 log 可以发现,如我们预期,The picture is sent split.计算一下 ,图片大小为 6164k ,Divided during transmission 6 个 1024k 和 1个 20k
跨语言的 client straming call 测试
1. 运行 Java 的 server ,再运行 golang 的client

2. 运行 go 的 server ,再运行 Java 的 client




边栏推荐
猜你喜欢
随机推荐
机械臂速成小指南(十六):带抛物线过渡的线性规划
【Transformer专题】Vision Transformer(ViT)原理 + 代码
JZ15 二进制中1的个数
Go-6-常用命令-go包管理问题-两个路径-GO111MODULE
JZ70 矩形覆盖
【面经】被虐了之后,我翻烂了equals源码,总结如下
怒写400篇AI文章!这群妹子卷疯了…
【学术相关】北大一研究生偷取同门师妹论文发表,作者却挂名给了武大 3 位不知情的学生......
跨境电商看不到另一面:商家刷单、平台封号、黑灰产牟利
tiup mirror set
性能测试详解(理论篇)
UnicodeEncodeError: 'gbk' codec can't encode character '\u2022' in position 178: illegal multibyte s
机械臂速成小指南(十五):线性规划
8大软件供应链攻击事件概述
VPP snort插件
【暑期集训第一周:搜索】【DFS&&BFS】
数据防泄漏产品该如何选择
Number 类及各子类所占字节数源码分析
CefSharp practical demonstration
技术分享| 融合调度系统中的电子围栏功能说明



![【[SCOI2005] 互不侵犯】【状压DP(含概念讲解)】](/img/93/667e81afeb99b1cce4eb8068e6ce14.png)





