2

I currently configure Jest by giving it a list of server URIs. Like this:

 public JestClient jestClient() {
    final JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
            .Builder(esServerUris)
            .build());
    final JestClient jestClient = factory.getObject();
    return jestClient;
}

If one of my ElasticSearch servers go offline (e.g. failure or maintenance), then a percentage of my Jest queries fail. Jest doesn't seem to do any kind of intelligent connection management by default.It must do something like round-robin through the servers or pick a server at random.

Is there a better way to handle this?

4

1 回答 1

5

您需要启用发现功能,以便客户端工厂在出现故障时找到另一台服务器。这样的事情应该做:

public JestClient jestClient() {
    final JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
            .Builder(esServerUris)
            .discoveryEnabled(true)
            .discoveryFrequency(500l, TimeUnit.MILLISECONDS)
            .build());
    final JestClient jestClient = factory.getObject();
    return jestClient;
}

您还可以在 中看到他们是如何对此进行测试的JestClientFactoryIntegrationTest.java,即他们从单个节点开始,然后再添加 3 个节点,然后关闭一个节点并断言客户端仍然与已启动的节点具有有效连接。

于 2015-11-13T04:27:17.317 回答