我正在尝试为Vertx web-client写一个包装器,以使用来自反应流的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
)?