Skip to content

Commit

Permalink
Allow to configure maxIdleTime property for HttpClient (#1411)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ziemowit authored and OlgaMaciaszek committed Nov 29, 2019
1 parent 9905335 commit 069f24d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@

/**
* @author Spencer Gibb
* @author Ziemowit Stolarczyk
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true)
Expand Down Expand Up @@ -586,10 +587,12 @@ public HttpClient gatewayHttpClient(HttpClientProperties properties) {
}
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ public static class Pool {
/** 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;
}
Expand Down Expand Up @@ -189,6 +195,14 @@ public void setAcquireTimeout(Long acquireTimeout) {
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 + '\''
Expand Down

0 comments on commit 069f24d

Please sign in to comment.