Quarkus returning a Multi<> as Rest response

96 Views Asked by At

I have a question regarding Quarkus and Rest Responses. I'm not that experienced with micro services.

I have an Quarkus backend, which is handling different types of rest requests. Uploading a file, get some user information, etc.

One of the requests is handling Timescale DB database query requests and returning a large amount of time series data to the requester. I'm using the reactive-pg-client for this.

I'm currently working with handling the request and the resource has a Multi<> return type, which is than streaming back the response.

My problem is especially with larger requests, that I first have to wait until the database query finishes and then steam back. When somebody requests huge amounts, an out of memory exception can occur. That's why I'm thinking of using some pagination and stream back the query in parts step by step.

But where I'm not sure is, how can I stream back a Multi<> in parts and not just at once?

Currently I have something like this:

@POST
        @Consumes(MediaType.APPLICATION_JSON)
        @Produces(MediaType.APPLICATION_JSON)
        @Path("/request")
        public Multi<[SomeType]> getTimeseries(String id) {
            return SomeFunction.getMulti( id );
        }

And I'm looking for a solution to change it to something like this:

@POST
        @Consumes(MediaType.APPLICATION_JSON)
        @Produces(MediaType.APPLICATION_JSON)
        @Path("/request")
        public Multi<[SomeType]> getTimeseries(String id) {
            while( SomeFunction.getPart( id ) != null ) {
              [Return-current-page-as-multi-and-move-on-to-next-page] 
            }
            return ;
        }

Is it possible to using something like a

Response.ok(currentPage).build();

Thank you.

0

There are 0 best solutions below