From 01f314a4756ed55e2e4602d9e7dca34e8893b42b Mon Sep 17 00:00:00 2001 From: Tim Peeters Date: Fri, 24 Jan 2020 13:41:25 +0100 Subject: [PATCH] Adds configurable maxLifeTime in HttpClientProperties. fixes gh-1542 --- docs/src/main/asciidoc/_configprops.adoc | 1 + .../config/GatewayAutoConfiguration.java | 4 ++-- .../gateway/config/HttpClientProperties.java | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 4578dd24..0c8ee8cc 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -30,6 +30,7 @@ |spring.cloud.gateway.httpclient.pool.acquire-timeout | | Only for type FIXED, the maximum time in millis to wait for aquiring. |spring.cloud.gateway.httpclient.pool.max-connections | | Only for type FIXED, the maximum number of connections before starting pending acquisition on existing ones. |spring.cloud.gateway.httpclient.pool.max-idle-time | | Time in millis after which the channel will be closed. If NULL, there is no max idle time. +|spring.cloud.gateway.httpclient.pool.max-life-time | | Duration after which the channel will be closed. If NULL, there is no max life time. |spring.cloud.gateway.httpclient.pool.name | proxy | The channel pool map name, defaults to proxy. |spring.cloud.gateway.httpclient.pool.type | | Type of pool for HttpClient to use, defaults to ELASTIC. |spring.cloud.gateway.httpclient.proxy.host | | Hostname for proxy configuration of Netty HttpClient. diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index 00ce39cf..dc27a9bb 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -591,11 +591,11 @@ public class GatewayAutoConfiguration { else if (pool.getType() == FIXED) { connectionProvider = ConnectionProvider.fixed(pool.getName(), pool.getMaxConnections(), pool.getAcquireTimeout(), - pool.getMaxIdleTime()); + pool.getMaxIdleTime(), pool.getMaxLifeTime()); } else { connectionProvider = ConnectionProvider.elastic(pool.getName(), - pool.getMaxIdleTime()); + pool.getMaxIdleTime(), pool.getMaxLifeTime()); } HttpClient httpClient = HttpClient.create(connectionProvider) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java index 1b0b61c7..0ecfdc29 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java @@ -178,6 +178,12 @@ public class HttpClientProperties { */ private Duration maxIdleTime = null; + /** + * Duration after which the channel will be closed. If NULL, there is no max life + * time. + */ + private Duration maxLifeTime = null; + public PoolType getType() { return type; } @@ -218,11 +224,20 @@ public class HttpClientProperties { this.maxIdleTime = maxIdleTime; } + public Duration getMaxLifeTime() { + return maxLifeTime; + } + + public void setMaxLifeTime(Duration maxLifeTime) { + this.maxLifeTime = maxLifeTime; + } + @Override public String toString() { return "Pool{" + "type=" + type + ", name='" + name + '\'' + ", maxConnections=" + maxConnections + ", acquireTimeout=" - + acquireTimeout + '}'; + + acquireTimeout + ", maxIdleTime=" + maxIdleTime + ", maxLifeTime=" + + maxLifeTime + '}'; } public enum PoolType {