gpt4 book ai didi

java - 如何在 RxJava Vert.x 中结束链式 http 请求?

转载 作者:搜寻专家 更新时间:2023-10-31 20:18:03 26 4
gpt4 key购买 nike

如何在 Rx Vert.X 中结束链式请求?

 HttpClient client = Vertx.vertx().createHttpClient();
HttpClientRequest request = client.request(HttpMethod.POST,
"someURL")
.putHeader("content-type", "application/x-www-form-urlencoded")
.putHeader("content-length", Integer.toString(jsonData.length())).write(jsonData);
request.toObservable().
//flatmap HttpClientResponse -> Observable<Buffer>
flatMap(httpClientResponse -> { //something
return httpClientResponse.toObservable();
}).
map(buffer -> {return buffer.toString()}).
//flatmap data -> Observable<HttpClientResponse>
flatMap(postData -> client.request(HttpMethod.POST,
someURL")
.putHeader("content-type", "application/x-www-form-urlencoded")
.putHeader("content-length", Integer.toString(postData.length())).write(postData).toObservable()).
//flatmap HttpClientResponse -> Observable<Buffer>
flatMap(httpClientResponse -> {
return httpClientResponse.toObservable();
})......//other operators
request.end();

请注意,我有 .end() 作为最高请求。如何结束 .flatmap 中的请求?我什至需要结束它吗?

最佳答案

有多种方法可以确保调用request.end()。但我会深入研究 Vert.x 的文档,如果有的话,我会直接打开源代码,看看它是否会为你调用 end() 。否则一个可能是

final HttpClientRequest request = ...
request.toObservable()
.doOnUnsubscribe(new Action0() {
@Override
public void call() {
request.end();
}
});

关于java - 如何在 RxJava Vert.x 中结束链式 http 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com