来自带有 Spring/Project 反应器的 HTTP 客户端的流响应

编程入门 行业动态 更新时间:2024-10-11 07:36:19
本文介绍了来自带有 Spring/Project 反应器的 HTTP 客户端的流响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将响应从响应式 HTTP 客户端流式传输到控制器,而无需在应用程序内存中随时保留整个响应主体?

How to stream response from reactive HTTP client to the controller without having the whole response body in the application memory at any time?

几乎所有项目反应器客户端的示例都返回 Mono.据我了解,反应式流是关于流式传输的,而不是全部加载然后发送响应.

Practically all examples of project reactor client return Mono<T>. As far as I understand reactive streams are about streaming, not loading it all and then sending the response.

是否有可能返回一种Flux,从而可以将大文件从某些外部服务传输到应用程序客户端,而无需使用大量 RAM 内存来存储中间结果?

Is it possible to return kind of Flux<Byte> to make it possible to transfer big files from some external service to the application client without a need of using a huge amount of RAM memory to store intermediate result?

推荐答案

我不认为在你的场景中你需要创建一个事件流,因为事件流更多地用于实时发出事件我认为你最好这样做这个.

I dont think that in your scenario you need to create an event stream because event stream is more used to emit event in real time i think you better do it like this.

@GetMapping(value = "bytes") public Flux<Byte> getBytes(){ return byteService.getBytes(); }

并且您可以将其发送为流.如果你仍然想要它作为一个流

and you can send it es a stream. if you still want it as a stream

@GetMapping(value = "bytes",produces = MediaType.TEXT_EVENT_STREAM_VALUE) public Flux<List<Byte>> getBytes(){ return byteService.getBytes(); }

更多推荐

来自带有 Spring/Project 反应器的 HTTP 客户端的流响应

本文发布于:2023-11-25 09:14:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629184.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:反应器   客户端   Spring   Project   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!