From cbfd3719e2fef60c348da5b1ab061c964b963e8d Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Mon, 2 Apr 2018 17:38:14 -0400 Subject: [PATCH] Adds option to disable netty http client pooling. --- .../gateway/config/GatewayAutoConfiguration.java | 13 ++++++++----- .../cloud/gateway/config/HttpClientProperties.java | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) 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 4f6fefa34..32f076ddd 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 @@ -110,6 +110,7 @@ import org.springframework.web.reactive.socket.server.support.HandshakeWebSocket import com.netflix.hystrix.HystrixObservableCommand; +import static org.springframework.cloud.gateway.config.HttpClientProperties.Pool.PoolType.DISABLED; import static org.springframework.cloud.gateway.config.HttpClientProperties.Pool.PoolType.FIXED; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; @@ -156,15 +157,17 @@ public class GatewayAutoConfiguration { // configure pool resources HttpClientProperties.Pool pool = properties.getPool(); - PoolResources poolResources; - if (pool.getType() == FIXED) { - poolResources = PoolResources.fixed(pool.getName(), + if (pool.getType() == DISABLED) { + opts.disablePool(); + } else if (pool.getType() == FIXED) { + PoolResources poolResources = PoolResources.fixed(pool.getName(), pool.getMaxConnections(), pool.getAcquireTimeout()); + opts.poolResources(poolResources); } else { - poolResources = PoolResources.elastic(pool.getName()); + PoolResources poolResources = PoolResources.elastic(pool.getName()); + opts.poolResources(poolResources); } - opts.poolResources(poolResources); // configure proxy if proxy host is set. HttpClientProperties.Proxy proxy = properties.getProxy(); 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 ff6a2ce3c..92c151b3d 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 @@ -61,7 +61,7 @@ public class HttpClientProperties { public static class Pool { - public enum PoolType { ELASTIC, FIXED } + public enum PoolType { ELASTIC, FIXED, DISABLED } /** Type of pool for HttpClient to use, defaults to ELASTIC. */ private PoolType type = PoolType.ELASTIC;