Skip to content

Commit

Permalink
add connection-pool-enabled parameter to disable reactive REST client…
Browse files Browse the repository at this point in the history
… connection pool
  • Loading branch information
gefloh committed Feb 13, 2023
1 parent 917f85f commit d3f5ac8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class RestClientConfig {
EMPTY.hostnameVerifier = Optional.empty();
EMPTY.connectionTTL = Optional.empty();
EMPTY.connectionPoolSize = Optional.empty();
EMPTY.connectionPoolEnabled = Optional.empty();
EMPTY.maxRedirects = Optional.empty();
EMPTY.headers = Collections.emptyMap();
EMPTY.shared = Optional.empty();
Expand Down Expand Up @@ -196,6 +197,12 @@ public class RestClientConfig {
@ConfigItem
public Optional<Integer> connectionPoolSize;

/**
* If set to false disables the connection pool completely.
*/
@ConfigItem(defaultValue = "true")
public Optional<Boolean> connectionPoolEnabled;

/**
* The maximum number of redirection a request can follow.
*
Expand Down Expand Up @@ -263,6 +270,7 @@ public static RestClientConfig load(String configKey) {
instance.hostnameVerifier = getConfigValue(configKey, "hostname-verifier", String.class);
instance.connectionTTL = getConfigValue(configKey, "connection-ttl", Integer.class);
instance.connectionPoolSize = getConfigValue(configKey, "connection-pool-size", Integer.class);
instance.connectionPoolEnabled = getConfigValue(configKey, "connection-pool-enabled", Boolean.class);
instance.maxRedirects = getConfigValue(configKey, "max-redirects", Integer.class);
instance.headers = getConfigValues(configKey, "headers", String.class, String.class);
instance.shared = getConfigValue(configKey, "shared", Boolean.class);
Expand Down Expand Up @@ -297,6 +305,7 @@ public static RestClientConfig load(Class<?> interfaceClass) {
instance.hostnameVerifier = getConfigValue(interfaceClass, "hostname-verifier", String.class);
instance.connectionTTL = getConfigValue(interfaceClass, "connection-ttl", Integer.class);
instance.connectionPoolSize = getConfigValue(interfaceClass, "connection-pool-size", Integer.class);
instance.connectionPoolEnabled = getConfigValue(interfaceClass, "connection-pool-enabled", Boolean.class);
instance.maxRedirects = getConfigValue(interfaceClass, "max-redirects", Integer.class);
instance.headers = getConfigValues(interfaceClass, "headers", String.class, String.class);
instance.shared = getConfigValue(interfaceClass, "shared", Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public class RestClientsConfig {
@ConfigItem
public Optional<Integer> connectionPoolSize;

/**
* If set to false disables the connection pool completely.
*
* Can be overwritten by client-specific settings.
*/
@ConfigItem(defaultValue = "true")
public Optional<Boolean> connectionPoolEnabled;

/**
* The maximum number of redirection a request can follow.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ private void verifyClientConfig(RestClientConfig clientConfig, boolean checkExtr
assertThat(clientConfig.connectionTTL.get()).isEqualTo(30000);
assertThat(clientConfig.connectionPoolSize).isPresent();
assertThat(clientConfig.connectionPoolSize.get()).isEqualTo(10);
assertThat(clientConfig.connectionPoolEnabled).isPresent();
assertThat(clientConfig.connectionPoolEnabled.get()).isFalse();
assertThat(clientConfig.maxRedirects).isPresent();
assertThat(clientConfig.maxRedirects.get()).isEqualTo(5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void checkGlobalConfigValues() {
.isEqualTo("io.quarkus.rest.client.reactive.HelloClientWithBaseUri$MyHostnameVerifier");
assertThat(configRoot.connectionTTL.get()).isEqualTo(20000); // value in ms, will be converted to seconds
assertThat(configRoot.connectionPoolSize.get()).isEqualTo(2);
assertThat(configRoot.connectionPoolEnabled.get()).isTrue();
assertThat(configRoot.maxRedirects.get()).isEqualTo(2);
assertThat(configRoot.followRedirects.get()).isTrue();
assertThat(configRoot.providers.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".que
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".hostname-verifier=io.quarkus.rest.client.reactive.HelloClientWithBaseUri$MyHostnameVerifier
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".connection-ttl=30000
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".connection-pool-size=10
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".connection-pool-enabled=false
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".max-redirects=5
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.message=hi
quarkus.rest-client."io.quarkus.rest.client.reactive.HelloClientWithBaseUri".headers.suffix=!
Expand All @@ -32,6 +33,7 @@ quarkus.rest-client.client-prefix.query-param-style=COMMA_SEPARATED
quarkus.rest-client.client-prefix.hostname-verifier=io.quarkus.rest.client.reactive.HelloClientWithBaseUri$MyHostnameVerifier
quarkus.rest-client.client-prefix.connection-ttl=30000
quarkus.rest-client.client-prefix.connection-pool-size=10
quarkus.rest-client.client-prefix.connection-pool-enabled=false
quarkus.rest-client.client-prefix.max-redirects=5
quarkus.rest-client.client-prefix.headers.user-agent=MP REST Client
quarkus.rest-client.client-prefix.headers.foo=bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ quarkus.rest-client.headers.foo=bar
quarkus.rest-client.hostname-verifier=io.quarkus.rest.client.reactive.HelloClientWithBaseUri$MyHostnameVerifier
quarkus.rest-client.connection-ttl=20000
quarkus.rest-client.connection-pool-size=2
quarkus.rest-client.connection-pool-enabled=true
quarkus.rest-client.max-redirects=2
quarkus.rest-client.follow-redirects=true
quarkus.rest-client.providers=io.quarkus.rest.client.reactive.HelloClientWithBaseUri$MyResponseFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ private void configureCustomProperties(RestClientBuilder builder) {
builder.property(QuarkusRestClientProperties.CONNECTION_TTL, connectionTTLSeconds);
}

Optional<Boolean> poolEnabled = oneOf(clientConfigByClassName().connectionPoolEnabled,
clientConfigByConfigKey().connectionPoolEnabled, configRoot.connectionPoolEnabled);
if (poolEnabled.isPresent()) {
builder.property(QuarkusRestClientProperties.CONNECTION_POOL_ENABLED, poolEnabled.get());
}

Map<String, String> headers = clientConfigByClassName().headers;
if (headers == null || headers.isEmpty()) {
headers = clientConfigByConfigKey().headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void testClientSpecificConfigs() {
Mockito.verify(restClientBuilderMock).hostnameVerifier(Mockito.any(MyHostnameVerifier1.class));
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_TTL, 10); // value converted to seconds
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_POOL_SIZE, 103);
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_POOL_ENABLED, false);
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.MAX_REDIRECTS, 104);
Mockito.verify(restClientBuilderMock).followRedirects(true);
Mockito.verify(restClientBuilderMock).register(MyResponseFilter1.class);
Expand Down Expand Up @@ -147,6 +148,7 @@ public void testGlobalConfigs() {
Mockito.verify(restClientBuilderMock).hostnameVerifier(Mockito.any(MyHostnameVerifier2.class));
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_TTL, 20);
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_POOL_SIZE, 203);
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.CONNECTION_POOL_ENABLED, true);
Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.MAX_REDIRECTS, 204);
Mockito.verify(restClientBuilderMock).followRedirects(true);
Mockito.verify(restClientBuilderMock).register(MyResponseFilter2.class);
Expand Down Expand Up @@ -176,6 +178,7 @@ private static RestClientsConfig createSampleConfigRoot() {
.of("io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilderTest$MyHostnameVerifier2");
configRoot.connectionTTL = Optional.of(20000); // value in ms, will be converted to seconds
configRoot.connectionPoolSize = Optional.of(203);
configRoot.connectionPoolEnabled = Optional.of(true);
configRoot.maxRedirects = Optional.of(204);
configRoot.followRedirects = Optional.of(true);
configRoot.providers = Optional
Expand Down Expand Up @@ -214,6 +217,7 @@ private static RestClientConfig createSampleClientConfig() {
.of("io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilderTest$MyHostnameVerifier1");
clientConfig.connectionTTL = Optional.of(10000); // value in milliseconds, will be converted to seconds
clientConfig.connectionPoolSize = Optional.of(103);
clientConfig.connectionPoolEnabled = Optional.of(false);
clientConfig.maxRedirects = Optional.of(104);
clientConfig.followRedirects = Optional.of(true);
clientConfig.providers = Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class QuarkusRestClientProperties {
*/
public static final String CONNECTION_POOL_SIZE = "io.quarkus.rest.client.connection-pool-size";

/**
* A boolean value used to determine whether the connection pool is enabled or disabled.
*/
public static final String CONNECTION_POOL_ENABLED = "io.quarkus.rest.client.connection-pool-enabled";

public static final String STATIC_HEADERS = "io.quarkus.rest.client.static-headers";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jboss.resteasy.reactive.client.impl;

import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_POOL_ENABLED;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_POOL_SIZE;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_TTL;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECT_TIMEOUT;
Expand Down Expand Up @@ -155,6 +156,16 @@ public Vertx get() {
}
options.setMaxPoolSize((int) connectionPoolSize);

Object connectionPoolEnabled = configuration.getProperty(CONNECTION_POOL_ENABLED);
if (connectionPoolEnabled != null) {
Boolean enabled = (Boolean) connectionPoolEnabled;
options.setKeepAlive(enabled);

if (!enabled) {
log.debug("connectionPool disabled");
}
}

if (loggingScope == LoggingScope.ALL) {
options.setLogActivity(true);
}
Expand Down

0 comments on commit d3f5ac8

Please sign in to comment.