0

I want to initiate a byte stream (from reading an InputStream) from one micronaut service to another, using declarative clients. I found this Github issue that deals with the client side of what I'm trying to solve.

The proposed solution, on the client side, is to pass in a @Body Flowable<byte[]> content on the client. I tried that using the sample code, but now I am stuck on how to consume the data on the server side.

For the endpoint's implementation, I similarly take in a Flowable<byte[]> body parameter and I subscribe to it. The problem is that it's not receiving any data. When the client calls the endpoint it ends up idle timing out.

I verified the created flowable has events holding the byte[] data by subscribing to it on the client side.

niebula
  • 351
  • 1
  • 6
  • 13

1 Answers1

0

Does something like the following work:

  public class InputStreamWrapper implements byte[] {
  private final InputStream inputStream;
  private final int chunkSize;

  public InputStreamWrapper(InputStream inputStream, int chunkSize) {
    this.inputStream = inputStream;
    this.chunkSize = chunkSize;
  }

  @Override
  public int read(byte[] b, int off, int len) throws IOException {
    return inputStream.read(b, off, len);
  }

  @Override
  public int read() throws IOException {
    byte[] chunk = new byte[chunkSize];
    int read = inputStream.read(chunk);
    if (read < 0) {
      return -1;
    }
    return chunk[0] & 0xff;
  }
}

e.g.

@Client("github")
public interface GithubUploadClient {

  @Post(value = "/repos/${github.owner}/{github.repo}/releases/{releaseId}/assets", produces = MediaType.APPLICATION_OCTET_STREAM)
  Asset uploadAsset(@QueryValue("name") String name, @Positive long releaseId, @Body InputStreamWrapper content);

}
K2J
  • 2,573
  • 6
  • 27
  • 34