From 1cc9c5bbc144d8d77a4e2782d03f685143cc56c3 Mon Sep 17 00:00:00 2001 From: Gerhard Flothow Date: Wed, 15 Feb 2023 11:43:33 -0500 Subject: [PATCH] add keep-alive-enabled parameter to enable/disable reactive REST client keep alive --- .../io/quarkus/restclient/config/RestClientConfig.java | 10 +++++----- .../quarkus/restclient/config/RestClientsConfig.java | 4 ++-- .../rest/client/reactive/ConfigurationTest.java | 4 ++-- .../rest/client/reactive/GlobalConfigurationTest.java | 2 +- .../configuration-test-application.properties | 4 ++-- .../global-configuration-test-application.properties | 2 +- .../reactive/runtime/RestClientCDIDelegateBuilder.java | 8 ++++---- .../runtime/RestClientCDIDelegateBuilderTest.java | 8 ++++---- .../client/api/QuarkusRestClientProperties.java | 4 ++-- .../resteasy/reactive/client/impl/ClientImpl.java | 10 +++++----- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientConfig.java b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientConfig.java index 04cd51f2ef225f..80a0e6445a2a21 100644 --- a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientConfig.java +++ b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientConfig.java @@ -41,7 +41,7 @@ public class RestClientConfig { EMPTY.hostnameVerifier = Optional.empty(); EMPTY.connectionTTL = Optional.empty(); EMPTY.connectionPoolSize = Optional.empty(); - EMPTY.connectionPoolEnabled = Optional.empty(); + EMPTY.keepAliveEnabled = Optional.empty(); EMPTY.maxRedirects = Optional.empty(); EMPTY.headers = Collections.emptyMap(); EMPTY.shared = Optional.empty(); @@ -198,10 +198,10 @@ public class RestClientConfig { public Optional connectionPoolSize; /** - * If set to false disables the connection pool completely. + * If set to false disables the keep alive completely. */ @ConfigItem(defaultValue = "true") - public Optional connectionPoolEnabled; + public Optional keepAliveEnabled; /** * The maximum number of redirection a request can follow. @@ -270,7 +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.keepAliveEnabled = getConfigValue(configKey, "keep-alive-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); @@ -305,7 +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.keepAliveEnabled = getConfigValue(interfaceClass, "keep-alive-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); diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsConfig.java b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsConfig.java index 1dff4d33ec63ee..c6e66c40876e3c 100644 --- a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsConfig.java +++ b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsConfig.java @@ -169,12 +169,12 @@ public class RestClientsConfig { public Optional connectionPoolSize; /** - * If set to false disables the connection pool completely. + * If set to false disables the keep alive completely. * * Can be overwritten by client-specific settings. */ @ConfigItem(defaultValue = "true") - public Optional connectionPoolEnabled; + public Optional keepAliveEnabled; /** * The maximum number of redirection a request can follow. diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConfigurationTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConfigurationTest.java index 28d84f5c14a776..ffc73d2756307f 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConfigurationTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConfigurationTest.java @@ -87,8 +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.keepAliveEnabled).isPresent(); + assertThat(clientConfig.keepAliveEnabled.get()).isFalse(); assertThat(clientConfig.maxRedirects).isPresent(); assertThat(clientConfig.maxRedirects.get()).isEqualTo(5); } diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/GlobalConfigurationTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/GlobalConfigurationTest.java index 745207dbfbcc5c..77609b1a1e5d80 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/GlobalConfigurationTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/GlobalConfigurationTest.java @@ -68,7 +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.keepAliveEnabled.get()).isTrue(); assertThat(configRoot.maxRedirects.get()).isEqualTo(2); assertThat(configRoot.followRedirects.get()).isTrue(); assertThat(configRoot.providers.get()) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/configuration-test-application.properties b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/configuration-test-application.properties index b2090ecdd2558b..d240d98e8330d4 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/configuration-test-application.properties +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/configuration-test-application.properties @@ -16,7 +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".keep-alive-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=! @@ -33,7 +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.keep-alive-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 diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/global-configuration-test-application.properties b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/global-configuration-test-application.properties index 5b0a99fe672ada..473ed229a62595 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/global-configuration-test-application.properties +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/global-configuration-test-application.properties @@ -21,7 +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.keep-alive-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 diff --git a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilder.java b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilder.java index 76da1ffa4d0e63..c74d840829b97b 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilder.java +++ b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilder.java @@ -98,10 +98,10 @@ private void configureCustomProperties(RestClientBuilder builder) { builder.property(QuarkusRestClientProperties.CONNECTION_TTL, connectionTTLSeconds); } - Optional poolEnabled = oneOf(clientConfigByClassName().connectionPoolEnabled, - clientConfigByConfigKey().connectionPoolEnabled, configRoot.connectionPoolEnabled); - if (poolEnabled.isPresent()) { - builder.property(QuarkusRestClientProperties.CONNECTION_POOL_ENABLED, poolEnabled.get()); + Optional keepAliveEnabled = oneOf(clientConfigByClassName().keepAliveEnabled, + clientConfigByConfigKey().keepAliveEnabled, configRoot.keepAliveEnabled); + if (keepAliveEnabled.isPresent()) { + builder.property(QuarkusRestClientProperties.KEEP_ALIVE_ENABLED, keepAliveEnabled.get()); } Map headers = clientConfigByClassName().headers; diff --git a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/test/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilderTest.java b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/test/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilderTest.java index 54074e450af4bb..058e6043593b51 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/test/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilderTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/test/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilderTest.java @@ -105,7 +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.KEEP_ALIVE_ENABLED, false); Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.MAX_REDIRECTS, 104); Mockito.verify(restClientBuilderMock).followRedirects(true); Mockito.verify(restClientBuilderMock).register(MyResponseFilter1.class); @@ -148,7 +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.KEEP_ALIVE_ENABLED, true); Mockito.verify(restClientBuilderMock).property(QuarkusRestClientProperties.MAX_REDIRECTS, 204); Mockito.verify(restClientBuilderMock).followRedirects(true); Mockito.verify(restClientBuilderMock).register(MyResponseFilter2.class); @@ -178,7 +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.keepAliveEnabled = Optional.of(true); configRoot.maxRedirects = Optional.of(204); configRoot.followRedirects = Optional.of(true); configRoot.providers = Optional @@ -217,7 +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.keepAliveEnabled = Optional.of(false); clientConfig.maxRedirects = Optional.of(104); clientConfig.followRedirects = Optional.of(true); clientConfig.providers = Optional diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/QuarkusRestClientProperties.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/QuarkusRestClientProperties.java index e43405f8d2e687..b07920d8789c65 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/QuarkusRestClientProperties.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/QuarkusRestClientProperties.java @@ -37,9 +37,9 @@ 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. + * A boolean value used to determine whether the keep alive is enabled or disabled. */ - public static final String CONNECTION_POOL_ENABLED = "io.quarkus.rest.client.connection-pool-enabled"; + public static final String KEEP_ALIVE_ENABLED = "io.quarkus.rest.client.keep-alive-enabled"; public static final String STATIC_HEADERS = "io.quarkus.rest.client.static-headers"; diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientImpl.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientImpl.java index 091806a15aa225..89009322dc9f0b 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientImpl.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientImpl.java @@ -1,9 +1,9 @@ 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; +import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.KEEP_ALIVE_ENABLED; import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_HEADER_SIZE; import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_INITIAL_LINE_LENGTH; import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_REDIRECTS; @@ -156,13 +156,13 @@ public Vertx get() { } options.setMaxPoolSize((int) connectionPoolSize); - Object connectionPoolEnabled = configuration.getProperty(CONNECTION_POOL_ENABLED); - if (connectionPoolEnabled != null) { - Boolean enabled = (Boolean) connectionPoolEnabled; + Object keepAliveEnabled = configuration.getProperty(KEEP_ALIVE_ENABLED); + if (keepAliveEnabled != null) { + Boolean enabled = (Boolean) keepAliveEnabled; options.setKeepAlive(enabled); if (!enabled) { - log.debug("connectionPool disabled"); + log.debug("keep alive disabled"); } }