You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project in micronaut 2.0.1 (also tried 2.5.13) that 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.
I suspect that the issue is related to blocking the main event loop. I did some debugging, the InputStream object is retrieved in an IO Executor, but the actual streaming (including reading from the input stream), is done using the event loop.
Is there any way to stream the resource without blocking the event loop?
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a project in micronaut 2.0.1 (also tried 2.5.13) that has a function to expose some resource. The resource is streamed with an InputStream from another service by HTTP.
Unfortunately, the app gets restarted because the health endpoint does not return quickly enough.
I suspect that the issue is related to blocking the main event loop. I did some debugging, the InputStream object is retrieved in an IO Executor, but the actual streaming (including reading from the input stream), is done using the event loop.
Is there any way to stream the resource without blocking the event loop?
Edit:
I think I found a solution for returning a string file, but unfortunately, it's considerably slower.
I still don't understand how to properly stream a byte resource.
Beta Was this translation helpful? Give feedback.
All reactions