diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java index 55c27d5b19a..de3d206107c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java @@ -28,6 +28,7 @@ import org.springframework.web.client.RestTemplate; import java.io.UnsupportedEncodingException; +import java.util.concurrent.TimeUnit; @Component public class RestTemplateFactory implements FactoryBean, InitializingBean { @@ -58,7 +59,9 @@ public boolean isSingleton() { } public void afterPropertiesSet() throws UnsupportedEncodingException { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + CloseableHttpClient httpClient = HttpClientBuilder.create() + .setConnectionTimeToLive(portalConfig.connectionTimeToLive(), TimeUnit.MILLISECONDS) + .build(); restTemplate = new RestTemplate(httpMessageConverters.getConverters()); HttpComponentsClientHttpRequestFactory requestFactory = diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index 9a677eea9a5..9548da9c05a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -169,6 +169,10 @@ public int readTimeout() { return getIntProperty("api.readTimeout", 10000); } + public int connectionTimeToLive() { + return getIntProperty("api.connectionTimeToLive", -1); + } + public List organizations() { String organizations = getValue("organizations");