本文整理了Java中org.elasticsearch.client.RestClientBuilder.setMaxRetryTimeoutMillis
方法的一些代码示例,展示了RestClientBuilder.setMaxRetryTimeoutMillis
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestClientBuilder.setMaxRetryTimeoutMillis
方法的具体详情如下:
包路径:org.elasticsearch.client.RestClientBuilder
类名称:RestClientBuilder
方法名:setMaxRetryTimeoutMillis
[英]Sets the maximum timeout (in milliseconds) to honour in case of multiple retries of the same request. #DEFAULT_MAX_RETRY_TIMEOUT_MILLIS if not specified.
[中]设置在同一请求多次重试时要遵守的最大超时(以毫秒为单位)#默认值\u最大值\u重试\u超时\u毫秒(如果未指定)。
代码示例来源:origin: apache/flink
@Override
public void configureRestClientBuilder(RestClientBuilder restClientBuilder) {
if (maxRetryTimeout != null) {
restClientBuilder.setMaxRetryTimeoutMillis(maxRetryTimeout);
}
if (pathPrefix != null) {
restClientBuilder.setPathPrefix(pathPrefix);
}
}
代码示例来源:origin: apache/nifi
return requestConfigBuilder;
})
.setMaxRetryTimeoutMillis(retryTimeout);
代码示例来源:origin: apache/storm
/**
* Creates a new {@link RestClient} using given {@link EsConfig}.
*
* @return {@link RestClient} for Elasticsearch connection
*/
public RestClient construct() {
RestClientBuilder builder = RestClient.builder(esConfig.getHttpHosts());
if (esConfig.getMaxRetryTimeoutMillis() != null) {
builder.setMaxRetryTimeoutMillis(esConfig.getMaxRetryTimeoutMillis());
}
if (esConfig.getDefaultHeaders() != null) {
builder.setDefaultHeaders(esConfig.getDefaultHeaders());
}
if (esConfig.getFailureListener() != null) {
builder.setFailureListener(esConfig.getFailureListener());
}
if (esConfig.getHttpClientConfigCallback() != null) {
builder.setHttpClientConfigCallback(esConfig.getHttpClientConfigCallback());
}
if (esConfig.getRequestConfigCallback() != null) {
builder.setRequestConfigCallback(esConfig.getRequestConfigCallback());
}
if (esConfig.getPathPrefix() != null) {
builder.setPathPrefix(esConfig.getPathPrefix());
}
return builder.build();
}
}
代码示例来源:origin: apache/metron
/**
* Creates an Elasticsearch client from settings provided via the global config.
*
* @return new client
*/
public static ElasticsearchClient create(Map<String, Object> globalConfig) {
ElasticsearchClientConfig esClientConfig = new ElasticsearchClientConfig(
getEsSettings(globalConfig));
HttpHost[] httpHosts = getHttpHosts(globalConfig, esClientConfig.getConnectionScheme());
RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setRequestConfigCallback(reqConfigBuilder -> {
// Modifies request config builder with connection and socket timeouts.
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_timeouts.html
reqConfigBuilder.setConnectTimeout(esClientConfig.getConnectTimeoutMillis());
reqConfigBuilder.setSocketTimeout(esClientConfig.getSocketTimeoutMillis());
return reqConfigBuilder;
});
builder.setMaxRetryTimeoutMillis(esClientConfig.getMaxRetryTimeoutMillis());
builder.setHttpClientConfigCallback(clientBuilder -> {
clientBuilder.setDefaultIOReactorConfig(getIOReactorConfig(esClientConfig));
clientBuilder.setDefaultCredentialsProvider(getCredentialsProvider(esClientConfig));
clientBuilder.setSSLContext(getSSLContext(esClientConfig));
return clientBuilder;
});
RestClient lowLevelClient = builder.build();
RestHighLevelClient client = new RestHighLevelClient(lowLevelClient);
return new ElasticsearchClient(lowLevelClient, client);
}
代码示例来源:origin: Qihoo360/Quicksql
/**
* Builds elastic rest client from user configuration
*
* @param coordinates list of {@code hostname/port} to connect to
* @return newly initialized low-level rest http client for ES
*/
private static RestClient connect(Map<String, Integer> coordinates,
Map<String, String> userConfig) {
Objects.requireNonNull(coordinates, "coordinates");
Preconditions.checkArgument(!coordinates.isEmpty(), "no ES coordinates specified");
final Set<HttpHost> set = new LinkedHashSet<>();
for (Map.Entry<String, Integer> entry : coordinates.entrySet()) {
set.add(new HttpHost(entry.getKey(), entry.getValue()));
}
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(userConfig.getOrDefault("esUser", "none"),
userConfig.getOrDefault("esPass", "none")));
return RestClient.builder(set.toArray(new HttpHost[0]))
.setHttpClientConfigCallback(httpClientBuilder ->
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
.setMaxRetryTimeoutMillis(300000).build();
}
代码示例来源:origin: ViDA-NYU/ache
public RestClient createRestClient(ElasticSearchConfig config) {
List<String> esHosts = config.getRestApiHosts();
List<HttpHost> hosts = new ArrayList<>();
for (String host : esHosts) {
try {
URL url = new URL(host);
hosts.add(new HttpHost(url.getHost(), url.getPort()));
} catch (MalformedURLException e) {
throw new RuntimeException("Failed to initialize Elasticsearch REST client. "
+ "Invalid host: " + host, e);
}
}
HttpHost[] httpHostsArray = (HttpHost[]) hosts.toArray(new HttpHost[hosts.size()]);
client = RestClient.builder(httpHostsArray)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder
.setConnectTimeout(config.getRestConnectTimeout())
.setSocketTimeout(config.getRestSocketTimeout());
}
})
.setMaxRetryTimeoutMillis(config.getRestMaxRetryTimeoutMillis())
.build();
logger.info("Initialized Elasticsearch REST client for hosts: "+Arrays.toString(httpHostsArray));
return client;
}
代码示例来源:origin: DigitalPebble/storm-crawler
).setMaxRetryTimeoutMillis(maxRetryTimeout);
代码示例来源:origin: ViDA-NYU/ache
public static RestClient createClient(ElasticSearchConfig config) {
HttpHost[] httpHosts = parseHostAddresses(config.getRestApiHosts());
RestClient client = RestClient.builder(httpHosts)
.setRequestConfigCallback(new RequestConfigCallback() {
@Override
public Builder customizeRequestConfig(
Builder requestConfigBuilder) {
return requestConfigBuilder
.setConnectTimeout(config.getRestConnectTimeout())
.setSocketTimeout(config.getRestSocketTimeout());
}
})
.setMaxRetryTimeoutMillis(config.getRestMaxRetryTimeoutMillis())
.build();
logger.info("Initialized Elasticsearch REST client for: " + Arrays.toString(httpHosts));
return client;
}
代码示例来源:origin: delirius325/jmeter-elasticsearch-backend-listener
.setMaxRetryTimeoutMillis(60000)
.build();
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
if (requestTimeoutString != null) {
final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT);
builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis()));
代码示例来源:origin: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core
protected ESClient createRestClient(ElasticSearchClientConfig config) {
String addressList = config.getOption("addressList", "");
if (addressList.isEmpty()) {
throw new IllegalArgumentException("No addressList option provided cannot connect RestClient");
}
String[] hosts = addressList.split(",");
HttpHost[] httpHosts = new HttpHost[hosts.length];
int i = 0;
for (String host : hosts) {
httpHosts[i++] = HttpHost.create(host);
}
RestClientBuilder builder = RestClient.builder(httpHosts)
.setRequestConfigCallback(
requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(
getConnectTimeoutMs(config))
.setSocketTimeout(
getSocketTimeoutMs(
config)))
.setMaxRetryTimeoutMillis(getConnectTimeoutMs(config));
addClientCallback(config, builder);
RestHighLevelClient client = new RestHighLevelClient(builder); // NOSONAR (factory)
// checkConnection(client);
return new ESRestClient(client.getLowLevelClient(), client);
}
代码示例来源:origin: org.apache.camel/camel-elasticsearch-rest
private RestClient createClient() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
final RestClientBuilder builder = RestClient.builder(configuration.getHostAddressesList().toArray(new HttpHost[0]));
builder.setMaxRetryTimeoutMillis(configuration.getMaxRetryTimeout());
builder.setRequestConfigCallback(requestConfigBuilder ->
requestConfigBuilder.setConnectTimeout(configuration.getConnectionTimeout()).setSocketTimeout(configuration.getSocketTimeout()));
if (configuration.getUser() != null && configuration.getPassword() != null) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUser(), configuration.getPassword()));
builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return httpClientBuilder;
});
}
final RestClient restClient = builder.build();
if (configuration.getEnableSniffer()) {
SnifferBuilder snifferBuilder = Sniffer.builder(restClient);
snifferBuilder.setSniffIntervalMillis(configuration.getSnifferInterval());
snifferBuilder.setSniffAfterFailureDelayMillis(configuration.getSniffAfterFailureDelay());
sniffer = snifferBuilder.build();
}
return restClient;
}
代码示例来源:origin: org.janusgraph/janusgraph-es
protected RestClient getRestClient(HttpHost[] hosts, Configuration config) {
final RestClientBuilder restClientBuilder = getRestClientBuilder(hosts);
final HttpClientConfigCallback httpClientConfigCallback = getHttpClientConfigCallback(config);
if (httpClientConfigCallback != null) {
restClientBuilder.setHttpClientConfigCallback(httpClientConfigCallback);
}
final RequestConfigCallback requestConfigCallback = getRequestConfigCallback(config);
if (requestConfigCallback != null) {
restClientBuilder.setRequestConfigCallback(requestConfigCallback);
}
if (config.has(ElasticSearchIndex.MAX_RETRY_TIMEOUT)) {
restClientBuilder.setMaxRetryTimeoutMillis(config.get(ElasticSearchIndex.MAX_RETRY_TIMEOUT));
}
return restClientBuilder.build();
}
代码示例来源:origin: hibernate/hibernate-search
private RestClient createClient(ConfigurationPropertySource propertySource, int maxRetryTimeoutMillis) {
ServerUris hosts = ServerUris.fromStrings( HOST.get( propertySource ) );
return RestClient.builder( hosts.asHostsArray() )
/*
* Note: this timeout is currently only used on retries,
* but should we start using the synchronous methods of RestClient,
* it would be applied to synchronous requests too.
* See https://github.com/elastic/elasticsearch/issues/21789#issuecomment-287399115
*/
.setMaxRetryTimeoutMillis( maxRetryTimeoutMillis )
.setRequestConfigCallback( b -> customizeRequestConfig( propertySource, b ) )
.setHttpClientConfigCallback( b -> customizeHttpClientConfig( propertySource, hosts, b ) )
.build();
}
代码示例来源:origin: Netflix/ndbench
restClient =
RestClient.builder(hosts).
setMaxRetryTimeoutMillis(esConfig.getMaxRetryTimeoutSeconds() * 1000).
setRequestConfigCallback( callback ).
build();
代码示例来源:origin: org.apache.nifi/nifi-elasticsearch-client-service
return requestConfigBuilder;
})
.setMaxRetryTimeoutMillis(retryTimeout);
代码示例来源:origin: org.hibernate.search/hibernate-search-backend-elasticsearch
private RestClient createClient(ConfigurationPropertySource propertySource, int maxRetryTimeoutMillis) {
ServerUris hosts = ServerUris.fromStrings( HOST.get( propertySource ) );
return RestClient.builder( hosts.asHostsArray() )
/*
* Note: this timeout is currently only used on retries,
* but should we start using the synchronous methods of RestClient,
* it would be applied to synchronous requests too.
* See https://github.com/elastic/elasticsearch/issues/21789#issuecomment-287399115
*/
.setMaxRetryTimeoutMillis( maxRetryTimeoutMillis )
.setRequestConfigCallback( b -> customizeRequestConfig( propertySource, b ) )
.setHttpClientConfigCallback( b -> customizeHttpClientConfig( propertySource, hosts, b ) )
.build();
}
代码示例来源:origin: hibernate/hibernate-search
private RestClient createClient(Properties properties, int maxRetryTimeoutMillis) {
String serverUrisString = ConfigurationParseHelper.getString(
properties,
ElasticsearchEnvironment.SERVER_URI,
ElasticsearchEnvironment.Defaults.SERVER_URI
);
ServerUris hosts = ServerUris.fromString( serverUrisString );
String pathPrefix = ConfigurationParseHelper.getString( properties, ElasticsearchEnvironment.PATH_PREFIX, null );
RestClientBuilder restClientBuilder = RestClient.builder( hosts.asHostsArray() )
/*
* Note: this timeout is currently only used on retries,
* but should we start using the synchronous methods of RestClient,
* it would be applied to synchronous requests too.
* See https://github.com/elastic/elasticsearch/issues/21789#issuecomment-287399115
*/
.setMaxRetryTimeoutMillis( maxRetryTimeoutMillis )
.setRequestConfigCallback( (b) -> customizeRequestConfig( properties, b ) )
.setHttpClientConfigCallback( (b) -> customizeHttpClientConfig( properties, hosts, b ) );
if ( !StringHelper.isEmpty( pathPrefix ) && !"/".equals( pathPrefix ) ) {
restClientBuilder.setPathPrefix( pathPrefix );
}
return restClientBuilder.build();
}
代码示例来源:origin: org.hibernate/hibernate-search-elasticsearch
private RestClient createClient(Properties properties, int maxRetryTimeoutMillis) {
String serverUrisString = ConfigurationParseHelper.getString(
properties,
ElasticsearchEnvironment.SERVER_URI,
ElasticsearchEnvironment.Defaults.SERVER_URI
);
ServerUris hosts = ServerUris.fromString( serverUrisString );
String pathPrefix = ConfigurationParseHelper.getString( properties, ElasticsearchEnvironment.PATH_PREFIX, null );
RestClientBuilder restClientBuilder = RestClient.builder( hosts.asHostsArray() )
/*
* Note: this timeout is currently only used on retries,
* but should we start using the synchronous methods of RestClient,
* it would be applied to synchronous requests too.
* See https://github.com/elastic/elasticsearch/issues/21789#issuecomment-287399115
*/
.setMaxRetryTimeoutMillis( maxRetryTimeoutMillis )
.setRequestConfigCallback( (b) -> customizeRequestConfig( properties, b ) )
.setHttpClientConfigCallback( (b) -> customizeHttpClientConfig( properties, hosts, b ) );
if ( !StringHelper.isEmpty( pathPrefix ) && !"/".equals( pathPrefix ) ) {
restClientBuilder.setPathPrefix( pathPrefix );
}
return restClientBuilder.build();
}
代码示例来源:origin: salesforce/Argus
.setHttpClientConfigCallback(clientConfigCallback)
.setRequestConfigCallback(requestConfigCallback)
.setMaxRetryTimeoutMillis(MAX_RETRY_TIMEOUT)
.build();
内容来源于网络,如有侵权,请联系作者删除!