A project in micronaut 2.0.1 has a function to expose some resource. The resource is streamed with an InputStream from another service by HTTP.
@ExecuteOn(TaskExecutors.IO)
@Status(HttpStatus.OK)
@Get
public StreamedFile export() throws FileNotFoundException {
InputStream is = service.getFromOtherServiceByHttpCall();
return new StreamedFile(is, CSV_MEDIA_TYPE);
}
Unfortunately, the app gets restarted because the health endpoint does not return quickly enough.
Is it possible that the StreamedFile
blocks the event loop when returning file through the internet? Locally everything works.
Edit:
I think I found a solution for returning a string file, but unfortunately, it's considerably slower.
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());
I still don't understand how to properly stream a byte resource.