Adds configurable maxLifeTime in HttpClientProperties.

fixes gh-1542
This commit is contained in:
Tim Peeters
2020-01-24 13:41:25 +01:00
committed by Spencer Gibb
parent 5786283774
commit 01f314a475
3 changed files with 19 additions and 3 deletions

View File

@@ -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.

View File

@@ -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)

View File

@@ -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 {