micronaut 2.0.1 中的项目具有公开某些资源的功能。资源通过 HTTP 与来自另一个服务的 InputStream 一起流式传输。
@ExecuteOn(TaskExecutors.IO)
@Status(HttpStatus.OK)
@Get
public StreamedFile export() throws FileNotFoundException {
InputStream is = service.getFromOtherServiceByHttpCall();
return new StreamedFile(is, CSV_MEDIA_TYPE);
}
不幸的是,应用程序会重新启动,因为运行状况端点返回的速度不够快。
StreamedFile
通过互联网返回文件时是否有可能阻止事件循环?在本地一切正常。
编辑:
我想我找到了返回字符串文件的解决方案,但不幸的是,它的速度要慢得多。
public Flux<String> export() throws FileNotFoundException {
InputStream is = service.getFromOtherServiceByHttpCall();
return Flux.using(() -> new BufferedReader(new InputStreamReader(is)).lines(),
Flux::fromStream,
BaseStream::close
).subscribeOn(Schedulers.boundedElastic());
我仍然不明白如何正确流式传输字节资源。