Stream http response using Microprofile rest client with Quarkus

1k Views Asked by At

Is it possible to read a response stream using the microprofile rest client?

I'm attempting to call an api that returns a stream and then parse the stream and emit each item as a Mutiny Multi.

The rest client

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.ws.rs.*;
import javax.rs.core.Response;
import javax.rs.core.MediaType;

@RegisterRestClient
public interface MyRemoteService {

  @GET
  @Path("/all"
  @Produces(MediaType.APPLICATION_JSON)
  Response getAllStream()
}

And the thing that calls it:

public Multi<MyObject> getAll() {
  return Multi.createFrom().emitter(em -> {
    Response response = myRemoteService.getAllStream();
    InputStream stream = response.readEntity(InputStream.class);
    ...
    // Some logic to parse json into objects
    ...
    em.emit(parsedObject)
    ...
    em.complete()
  }
}

This just calls the endpoint and waits for the full response before then parsing it into individual objects. I can just change the rest client to return a list of objects and I get the same behaviour. Is it possible to get each item as it's streamed rather than just waiting?

0

There are 0 best solutions below