Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ protected ConnectionProvider buildConnectionProvider(HttpClientProperties proper
builder.evictInBackground(pool.getEvictionInterval());
builder.metrics(pool.isMetrics());

if (pool.getInactivePoolDisposeInterval() != null && pool.getPoolInactivity() != null) {
builder.disposeInactivePoolsInBackground(pool.getInactivePoolDisposeInterval(),
pool.getPoolInactivity());
}

// Define the pool leasing strategy
if (pool.getLeasingStrategy() == FIFO) {
builder.fifo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ public static class Pool {
*/
private boolean metrics = false;

/**
* Interval at which connection pools are regularly checked in the background, and
* the pools that have been inactive for longer than {@code poolInactivity} are
* disposed. If NULL, inactive pools are not disposed in the background.
*/
private Duration inactivePoolDisposeInterval = null;

/**
* Duration of inactivity after which a connection pool is considered inactive and
* eligible to be disposed by the background check. Only applies when
* {@code inactivePoolDisposeInterval} is set.
*/
private Duration poolInactivity = null;

/**
* Configures the leasing strategy for the pool (fifo or lifo), defaults to FIFO
* which is Netty's default.
Expand Down Expand Up @@ -278,6 +292,22 @@ public void setMetrics(boolean metrics) {
this.metrics = metrics;
}

public Duration getInactivePoolDisposeInterval() {
return inactivePoolDisposeInterval;
}

public void setInactivePoolDisposeInterval(Duration inactivePoolDisposeInterval) {
this.inactivePoolDisposeInterval = inactivePoolDisposeInterval;
}

public Duration getPoolInactivity() {
return poolInactivity;
}

public void setPoolInactivity(Duration poolInactivity) {
this.poolInactivity = poolInactivity;
}

public LeasingStrategy getLeasingStrategy() {
return leasingStrategy;
}
Expand All @@ -291,7 +321,8 @@ public String toString() {
return "Pool{" + "type=" + type + ", name='" + name + '\'' + ", maxConnections=" + maxConnections
+ ", acquireTimeout=" + acquireTimeout + ", maxIdleTime=" + maxIdleTime + ", maxLifeTime="
+ maxLifeTime + ", evictionInterval=" + evictionInterval + ", metrics=" + metrics
+ ", leasingStrategy=" + leasingStrategy + '}';
+ ", inactivePoolDisposeInterval=" + inactivePoolDisposeInterval + ", poolInactivity="
+ poolInactivity + ", leasingStrategy=" + leasingStrategy + '}';
}

public enum PoolType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public void nettyHttpClientConfigured() {
"spring.cloud.gateway.server.webflux.httpclient.pool.eviction-interval=10s",
"spring.cloud.gateway.server.webflux.httpclient.pool.type=fixed",
"spring.cloud.gateway.server.webflux.httpclient.pool.metrics=true",
"spring.cloud.gateway.server.webflux.httpclient.pool.inactive-pool-dispose-interval=30s",
"spring.cloud.gateway.server.webflux.httpclient.pool.pool-inactivity=5m",
"spring.cloud.gateway.server.webflux.httpclient.pool.leasing-strategy=lifo",
"spring.cloud.gateway.server.webflux.httpclient.compression=true",
"spring.cloud.gateway.server.webflux.httpclient.wiretap=true",
Expand All @@ -145,6 +147,8 @@ public void nettyHttpClientConfigured() {
assertThat(properties.isCompression()).isEqualTo(true);
assertThat(properties.getPool().getEvictionInterval()).hasSeconds(10);
assertThat(properties.getPool().isMetrics()).isEqualTo(true);
assertThat(properties.getPool().getInactivePoolDisposeInterval()).hasSeconds(30);
assertThat(properties.getPool().getPoolInactivity()).hasMinutes(5);
assertThat(properties.getPool().getLeasingStrategy()).isEqualTo(LeasingStrategy.LIFO);
assertThat(properties.getSsl().getSslBundle()).isEqualTo("mybundle");

Expand Down