1

Reactor-core 和 Spring 5 刚刚为其 Mono/Flux Publishers 引入了新的异步 WebClient。

由于使用 Observable 包装 RestTemplate 请求并 subscribeOn 以提供异步性是很常见的,所以我想知道 RxJava 是否有任何异步客户端。

我找到了https://github.com/ReactiveX/RxApacheHttp但它似乎不受支持,它的最后一次提交是从 2014 年开始的,甚至在我的测试中都不起作用。

4

3 回答 3

3

您可以使用基于 Netty 的RxNetty( https://github.com/ReactiveX/RxNetty )。

您还可以将 Netflix Ribbon ( https://github.com/Netflix/ribbon ) 与 RxNetty 一起使用。

于 2016-10-21T15:09:53.190 回答
2

另一种选择 - AsyncHttpClient。Maven链接

初始点:

RxHttpClient.create(AsyncHttpClient asyncHttpClient) ;
于 2019-10-16T17:13:08.213 回答
1

是的,有,但不清楚是否适合您的需求:

改造2

为了能够获得响应,Observable请将以下内容添加到您的build.gradle文件中:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

在您拥有的众多选项中:

Retrofit retrofit = new Retrofit.Builder()
    (...)
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    (...)
    .build();

之后,在作为每个函数接口的类内部Retrofit可以Observable<{class_to_return}>作为返回对象:

retrofit.create({interface_class}.class)

接口类(示例):

Observable<ApiUser> postLogin({parameters});
于 2016-10-19T09:12:34.430 回答