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




边栏推荐
猜你喜欢
随机推荐
快速搞懂Seata分布式事务AT、TCC、SAGA、XA模式选型
WWW'22 推荐系统论文之多任务与对比学习篇
VLAN实验
一文搞懂│php 中的 DI 依赖注入
ACL/NAACL'22 推荐系统论文梳理
ICML/ICLR'22 推荐系统论文梳理
NC231 只出现一次的数字
AI智能剪辑,仅需2秒一键提取精彩片段
先睹为快!界面控件DevExpress WPF这些功能即将发布
性能测试详解(理论篇)
推荐系统相关顶会整理
A tour of gRPC:06 - gRPC client straming 客户端流
坚持自主创新 线控底盘领军企业英创汇智获数亿元B+轮融资
11.1-CM24 最近公共祖先
(LinkedList与链表) 和 (ArrayList与顺序表)的区别
SIGIR'22 推荐系统论文之序列推荐(长文)篇
关于小程序TabBar跳转页面跟TabBar标签栏的icon不对应的分析(debug)
【服务器数据恢复】Raid阵列更换故障硬盘后数据同步失败的数据恢复案例
uWSGI看这几篇就够了
8大软件供应链攻击事件概述









![【[NOI2001] 炮兵阵地】【状压DP】](/img/ae/6b01b175b0158fb804211931d57c0c.jpg)