0

I am using opensearch-java client to connect to my OpenSearch cluster hosted in AWS. The client uses Apache HttpClient5 Transport to connect to the cluster. This is how my client is setup:

protected OpenSearchAsyncClient createInstance() throws Exception {
        final HttpHost[] hosts = config.getNodeAddresses().stream().map(
            address -> new HttpHost("https", address, config.getPort())).toArray(HttpHost[]::new);

        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        final SSLContext sslcontext = SSLContextBuilder
                .create()
                .build();

        final ApacheHttpClient5TransportBuilder builder = ApacheHttpClient5TransportBuilder.builder(hosts);
        builder.setHttpClientConfigCallback(httpClientBuilder -> {
            final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
                        .setSslContext(sslcontext)
                        .build();

            final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
                    .create()
                    .setTlsStrategy(tlsStrategy)
                    .setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT)
                    .setMaxConnTotal(config.getMaxConnTotal())
                    .setMaxConnPerRoute(config.getMaxConnPerRoute())
                    .setConnectionTimeToLive(TimeValue.ofSeconds(config.getConnectionTimeToLive()))
                    .setValidateAfterInactivity(TimeValue.ofSeconds(
                            config.getValidateAfterInactivity()))
                    .setConnPoolPolicy(PoolReusePolicy.FIFO)
                    .build();

            return httpClientBuilder
                    .setDefaultCredentialsProvider(credentialsProvider)
                    .setConnectionManager(connectionManager)
                    .evictIdleConnections(TimeValue.ofSeconds(config.getEvictIdleConnections()))
                    .evictExpiredConnections()
                    .setIOReactorConfig(
                            IOReactorConfig.custom()
                                    .setSoTimeout(Timeout.ofSeconds(config.getSoTimeout()))
                                    .setSoKeepAlive(true)
                                    .setIoThreadCount(config.getIoThreadCount())
                                    .setSelectInterval(TimeValue.ofMilliseconds(config.getIOSelectInterval()))
                                    .build())
                    .setIoReactorExceptionCallback(e ->
                            LOGGER.error("OpenSearch client's IOReactor encountered uncaught exception", e));
        });

        builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
                .setConnectionRequestTimeout(Timeout.ofMilliseconds(config.getConnectionRequestTimeout()))
                .setConnectTimeout(Timeout.ofMilliseconds(config.getConnectTimeout()))
                .setResponseTimeout(Timeout.ofMilliseconds(config.getReadTimeout()))
                .setConnectionKeepAlive(TimeValue.ofSeconds(config.getConnectionKeepAlive())));
        builder.setFailureListener(new ApacheHttpClient5Transport.FailureListener() {
            @Override
            public void onFailure(Node node) {
                LOGGER.error("OpenSearch client encountered failure in this node: {}", node.getHost());
            }
        });
        builder.setMapper(new JacksonJsonpMapper(Mapper.getObjectMapper()));

        final OpenSearchTransport transport = builder.build();
        return new OpenSearchAsyncClient(transport);
}

Here's the version of OpenSearch I am using:

        <dependency>
            <groupId>org.opensearch.client</groupId>
            <artifactId>opensearch-java</artifactId>
            <version>2.4.0</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.opensearch</groupId>
            <artifactId>opensearch</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <version>5.1.5</version>
        </dependency>

I would like to change the client's properties dynamically during runtime, instead of changing the properties and restarting all the nodes. But, the client doesn't have any accessible methods that I can use to change the properties dynamically. Is there a way to change these properties dynamically by changing config.? Thank you!

2
  • which properties do you refer to? Commented Aug 11, 2023 at 11:14
  • In the client setup I posted, anything that is using config.<properties>, for e.g. config.getNodeAddresses(). Commented Aug 11, 2023 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.