Vertx RxJava webclient 客户端

Vertx RxJava webclient client

我正在尝试使用 vertx 和 rx java 使用 REST API,下面是我的代码

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

而我在主 class 中的订阅者代码是

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

当我 运行 main 方法时,我得到以下错误

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: DefaultPromise@5dcb32d8(success: time.jsontest.com/2404:6800:4007:807:0:0:0:2013)

我检查了 url,它工作正常,只有当我使用 vertx webclient 连接到这个 url 时,我才收到这个错误,我错过了什么? 我在 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 问题。

尝试通过在命令行中添加此系统属性 来切换到 JVM 内置解析器:

-Dvertx.disableDnsResolver=true

顺便说一下,在任何时候调用您的方法时创建一个 Vert.x 实例和 Web 客户端是一种不好的做法。您应该重复使用两者的单个实例。