当前位置:网站首页>On flow delivery between microservices
On flow delivery between microservices
2022-07-02 13:38:00 【Under the seven kingdoms, I want 99】
About the flow transfer between microservices
As the title says , Recently, the landlord encountered a scene problem , Initially, I wanted to transfer flows between microservices , Results found , In the process of transmission , Stream will be lost , That is, the flow cannot be transferred in the ordinary way , Is there any alternative way or method to solve the problem
1 Scene question
In everyday projects , There are often imports and exports Excel The function of . In a requirement function , The design of the function is : Front end upload Excel Go backstage , Background analysis Excel, And upload the file to the ECS , And return the file fileId. Click the submit button on the page , The background will be based on the file fileId Download the file stream from the ECS .
In the initial design , Because the back-end micro services are divided into different services according to different functions , Therefore, it is a separate micro service that operates cloud service data , Ordinary business microservice modules only pass feign Etc , So the use of feign Interface call mode
feign Interface call Is to directly treat the file stream as a normal parameter in feign Interface , feign There is a problem with the way of calling , That is, the queried stream , Cannot return to business service .
2 Solution
Inquire relevant information , It is found that the flow cannot pass directly feign Interface call , Because the stream is in the transmission process , Cannot convert effectively , Therefore, all acceptance streams are empty . For this problem , There are two ways , The first is to replace the stream loading with byte array transmission , Byte array in feign Interface calling , Can effectively transmit ; The second way is through response Object delivery flow ; The third kind of , Listen to the big guy , feign If the interface call needs to pass the flow , Additional configuration is required , Add related transformations . ( Unknown , To be verified )
1 Through byte array
Cloud service interface
@PostMapping("/upload")
@ResponseBody
public byte[] upload() throws IOException {
// Simulate getting file streams from cloud services
InputStream is = new ZipInputStream(null);
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = is.read(buffer)) != -1) {
bos.write(buffer,0,len);
}
bos.flush();
return bos.toByteArray();
}
feign Interface
@PostMapping("/upload")
@ResponseBody
byte[] upload();
Business services
byte[] bytes = ossClient.upload();
InputStream is = new ByteArrayInputputStream(bytes);
2 adopt Response
@PostMapping("/upload")
@ResponseBody
public void upload(HttpServletResponse resp) throws IOException {
// Simulate getting file streams from cloud services
InputStream is = new ZipInputStream(null)
OutputStream os = response.getOutputStream();
byte[] bytes = new byte[1024];
int len = 0;
while ((len = is.read(bytes)) != -1) {
os.write(bytes, 0, len);
}
is.close();
os.flush();
os.close();
}
feign Interface
@PostMapping("/upload")
@ResponseBody
feign.Response upload(HttpServletResponse resp);
Business services
Response response = ossClient.upload();
InputStream is = response.body().asInputStream();
3 summary
Through the above methods, we can know , All of them transfer streams through transformation , There is no way to transfer the flow directly , For mode three , We also need to learn and explore , Also welcome scholars who understand to add and correct .
边栏推荐
- Find love for speed in F1 delta time Grand Prix
- I did it with two lines of code. As a result, my sister had a more ingenious way
- 屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
- JS reverse row query data decryption
- Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
- D为何链接不了dll
- SSL证书的分类有哪些?如何选择合适的SSL证书?
- Solution: Compression Technology (original version and sequel version)
- Astro learning notes
- Why is the default of switch followed by break?
猜你喜欢
Unity SKFramework框架(十三)、Question 问题模块
2022零代码/低代码开发白皮书【伙伴云出品】附下载
Jerry's watch modifies the alarm clock [chapter]
挥发性有机物TVOC、VOC、VOCS气体检测+解决方案
Chinese name extraction (toy code - accurate head is too small, right to play)
解答:EasyDSS视频点播时音频是否可以设置为默认开启?
Node.js通过ODBC访问PostgreSQL数据库
Web Foundation
Essential for operation and maintenance - Elk log analysis system
Node. JS accessing PostgreSQL database through ODBC
随机推荐
互联网常见34个术语解释
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
Student course selection information management system based on ssm+jsp framework [source code + database]
Solution: Compression Technology (original version and sequel version)
A better database client management tool than Navicat
口袋奇兵点评
Explanation: here is your UFO, Goldbach conjecture
研究表明“气味相投”更易成为朋友
Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
Unity SKFramework框架(十五)、Singleton 单例
伙伴云表格强势升级!Pro版,更非凡!
EasyDSS点播服务分享时间出错如何修改?
Jerry's watch ringtone audition [article]
We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
Node. JS accessing PostgreSQL database through ODBC
Nohup command
D how to check null
挥发性有机物TVOC、VOC、VOCS气体检测+解决方案
Unity SKFramework框架(十九)、POI 兴趣点/信息点
Why is the default of switch followed by break?