Allow to configure maxIdleTime property for HttpClient (#1411)
* Allow to configure maxIdleTime property for HttpClient Since 0.9.0.RELEASE of reactor netty there is a possibility to configure the pooled connection max idle time. This commit gives the possibility to set it via spring configuration. * Changes after review
This commit is contained in:
committed by
Olga Maciaszek-Sharma
parent
99053359d7
commit
069f24d568
@@ -28,6 +28,7 @@
|
||||
|spring.cloud.gateway.httpclient.connect-timeout | | The connect timeout in millis, the default is 45s.
|
||||
|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.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.
|
||||
|
||||
@@ -152,6 +152,7 @@ import static org.springframework.cloud.gateway.config.HttpClientProperties.Pool
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Ziemowit Stolarczyk
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true)
|
||||
@@ -586,10 +587,12 @@ public class GatewayAutoConfiguration {
|
||||
}
|
||||
else if (pool.getType() == FIXED) {
|
||||
connectionProvider = ConnectionProvider.fixed(pool.getName(),
|
||||
pool.getMaxConnections(), pool.getAcquireTimeout());
|
||||
pool.getMaxConnections(), pool.getAcquireTimeout(),
|
||||
pool.getMaxIdleTime());
|
||||
}
|
||||
else {
|
||||
connectionProvider = ConnectionProvider.elastic(pool.getName());
|
||||
connectionProvider = ConnectionProvider.elastic(pool.getName(),
|
||||
pool.getMaxIdleTime());
|
||||
}
|
||||
|
||||
HttpClient httpClient = HttpClient.create(connectionProvider)
|
||||
|
||||
@@ -157,6 +157,12 @@ public class HttpClientProperties {
|
||||
/** Only for type FIXED, the maximum time in millis to wait for aquiring. */
|
||||
private Long acquireTimeout = ConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT;
|
||||
|
||||
/**
|
||||
* Time in millis after which the channel will be closed.
|
||||
* If NULL, there is no max idle time.
|
||||
*/
|
||||
private Duration maxIdleTime = null;
|
||||
|
||||
public PoolType getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -189,6 +195,14 @@ public class HttpClientProperties {
|
||||
this.acquireTimeout = acquireTimeout;
|
||||
}
|
||||
|
||||
public Duration getMaxIdleTime() {
|
||||
return maxIdleTime;
|
||||
}
|
||||
|
||||
public void setMaxIdleTime(Duration maxIdleTime) {
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pool{" + "type=" + type + ", name='" + name + '\''
|
||||
|
||||
Reference in New Issue
Block a user