1
我試圖消耗使用vertx和RX Java中的REST API,下面是我的代碼Vertx RxJava WebClient的客戶
import io.vertx.rxjava.core.buffer.Buffer;
import io.vertx.rxjava.ext.web.client.HttpResponse;
import rx.Single;
public Single<HttpResponse<Buffer>> getLanguages() {
WebClientOptions options = new WebClientOptions().setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.82 Safari/537.36");
WebClient client = WebClient.create(Vertx.vertx(), options);
Single<HttpResponse<Buffer>> single = client
.get("time.jsontest.com", "/")
.rxSend();
return single;
}
,並在主類我的用戶代碼是
public static void main(String[] args) {
Single<HttpResponse<Buffer>> single = new ITAPILanguagesImpl().getLanguages();
single.subscribe(response -> {
System.out.println("Received 1st response with status code" + response.statusCode());
}, error -> {
System.out.println("Something went wrong " + error.getMessage());
});
}
當我運行的主要方法,我得到
Jun 06, 2017 9:48:32 PM io.netty.resolver.dns.DnsNameResolver trySuccess
Something went wrong Network is unreachable: no further information: time.jsontest.com/2404:6800:4007:807:0:0:0:2013:80
WARNING: Failed to notify success (time.jsontest.com/2404:6800:4007:807:0:0:0:2013) to a promise: [email protected](success: time.jsontest.com/2404:6800:4007:807:0:0:0:2013)
我檢查的網址,並將其工作正常,只有當我連接到這個網址全光照以下錯誤g vertx webclient我得到這個錯誤,我錯過了什麼? 我在pom文件中添加了以下工件作爲依賴關係。
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java</artifactId>
<version>3.4.1</version>
</dependency>
謝謝!
謝謝你!我認爲DNS問題是暫時的,但是要感謝關於最佳實踐的說明。 – Rakesh