-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14873 from eAybars/issue-14754
Allow further configuration of Elasticsearch RestClient through HttpClientConfigCallback
- Loading branch information
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...a/io/quarkus/elasticsearch/restclient/lowlevel/runtime/ElasticsearchClientConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.elasticsearch.restclient.lowlevel.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; | ||
import org.elasticsearch.client.RestClientBuilder; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.elasticsearch.restclient.lowlevel.ElasticsearchClientConfig; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ElasticsearchClientConfigTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClass(TestConfigurator.class) | ||
.addAsResource(new StringAsset("quarkus.elasticsearch.hosts=elasticsearch:9200"), | ||
"application.properties")); | ||
|
||
@Inject | ||
ElasticsearchConfig config; | ||
@Inject | ||
@ElasticsearchClientConfig | ||
TestConfigurator testConfigurator; | ||
|
||
@Test | ||
public void testRestClientBuilderHelperWithElasticsearchClientConfig() { | ||
RestClientBuilderHelper.createRestClientBuilder(config).build(); | ||
assertTrue(testConfigurator.isInvoked()); | ||
} | ||
|
||
@ElasticsearchClientConfig | ||
@ApplicationScoped | ||
public static class TestConfigurator implements RestClientBuilder.HttpClientConfigCallback { | ||
private boolean invoked = false; | ||
|
||
@Override | ||
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder builder) { | ||
invoked = true; | ||
return builder; | ||
} | ||
|
||
public boolean isInvoked() { | ||
return invoked; | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...src/main/java/io/quarkus/elasticsearch/restclient/lowlevel/ElasticsearchClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.elasticsearch.restclient.lowlevel; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.enterprise.util.AnnotationLiteral; | ||
import javax.inject.Qualifier; | ||
|
||
/** | ||
* Annotate implementations of {@code org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback} to provide further | ||
* configuration of injected Elasticsearch {@code RestClient} You may provide multiple implementations each annotated with | ||
* {@code ElasticsearchClientConfig} and configuration provided by each implementation will be applied in a randomly ordered | ||
* cascading manner | ||
*/ | ||
@Qualifier | ||
@Target({ FIELD, TYPE, PARAMETER }) | ||
@Retention(RUNTIME) | ||
public @interface ElasticsearchClientConfig { | ||
|
||
class Literal extends AnnotationLiteral<ElasticsearchClientConfig> implements ElasticsearchClientConfig { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters