来自Vertx Webclient响应主体的响应流发布者

问题描述 投票:0回答:1

[我正在尝试为Vertx web-client写一个包装器,以使用来自reactstream的Publisher从服务器加载响应主体:

import org.reactivestreams.Publisher;
import io.vertx.reactivex.ext.web.client.WebClient;

interface Storage {
  Publisher<ByteBuffer> load(String key);
}

class WebStorage implements Storage {
  private final WebClient client;

  public WebStorage(final WebClient client) {
    this.client = client;
  }

  @Override
  public Publisher<ByteBuffer> laod(final String key) {
    return client.get(String.format("https://myhost/path?query=%s", key))
      .rxSend()
      .toFlowable()
      .map(resp -> ByteBuffer.wrap(resp.body().getBytes()));
  }
}

此解决方案是不正确的,因为它通过getBytes()调用以阻塞方式读取所有主体字节。

是否可以按块读取Vertx WebClient的响应并将其转换为Publisher(或Rx Flowable)?

java rx-java vert.x reactive-streams vertx-httpclient
1个回答
0
投票

Vert.x Web客户端并非旨在流式传输响应主体。它按设计缓冲内容。

如果要流式传输内容,则可以使用更灵活的基础HTTP客户端。

© www.soinside.com 2019 - 2024. All rights reserved.