当前位置:网站首页>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




边栏推荐
猜你喜欢
随机推荐
Thinkpad E430c使用u盘安装系统
浅聊组合函数
tiup mirror rotate
不平衡之钥: 重加权法知几何
策略路由下发
网御数据库审计系统配置Radius启用双因素/双因子(2FA/MFA)身份认证
MPLS实验
软件技术功能开发思路
不平衡之钥: 重采样法何其多
WWW'22 推荐系统论文之序列推荐篇
AI智能剪辑,仅需2秒一键提取精彩片段
从幻核疑似裁撤看如何保证NFT的安全
24、wpf之布局(二)
我今天终于发现demo才是一切
2.7 - 文件管理 2.8 - 多级目录结构 2.9 - 位示图
IJCAI'22 推荐系统论文梳理
synchronized已经不在臃肿了,放下对他的成见之初识轻量级锁
坚持自主创新 线控底盘领军企业英创汇智获数亿元B+轮融资
关于小程序TabBar跳转页面跟TabBar标签栏的icon不对应的分析(debug)
JZ40 最小的K个数









