2017-06-06 6 views
1

私は以下、VERTXとRX Javaを使用してREST APIを消費しようとしている私のコードはVERTX RxJava Webクライアントクライアント

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()); 
     }); 
    } 

Iであります私はURLをチェックし、私がこのURLのusinに接続した場合にのみ、正常に動作している私は、次のエラー

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> 

ありがとう!

答えて

1

ご使用の環境ではDNSの問題のようです。

は、組み込みのリゾルバコマンドラインで、このシステムプロパティを追加することにより、JVMに切り替えてみてください:

-Dvertx.disableDnsResolver=true 

ところで、Vert.xインスタンスとWebクライアントをいつでも作成する、あなたのメソッドを呼び出すです悪い習慣。両方のインスタンスを再利用する必要があります。

+0

ありがとうございました!私はDNSの問題は一時的だと思うが、ベストプラクティスのメモに感謝する。 – Rakesh