Skip to content

Commit

Permalink
feat: support portal restTemplate Client connection pool config (#5200)
Browse files Browse the repository at this point in the history
* feat: support portal restTemplate Client connection pool config

* feat: add CHANGES.md #5199

* style: remove chinese comments

* feat: add CHANGES.md #5200
  • Loading branch information
youngzil authored Aug 21, 2024
1 parent d1e31a7 commit f4a0236
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Apollo 2.4.0

------------------
* [Update the server config link in system info page](https://github.com/apolloconfig/apollo/pull/5204)
* [Feature support portal restTemplate Client connection pool config](https://github.com/apolloconfig/apollo/pull/5200)


------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
Expand Down Expand Up @@ -59,8 +60,14 @@ public boolean isSingleton() {
}

public void afterPropertiesSet() throws UnsupportedEncodingException {

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(portalConfig.connectPoolMaxTotal());
connectionManager.setDefaultMaxPerRoute(portalConfig.connectPoolMaxPerRoute());

CloseableHttpClient httpClient = HttpClientBuilder.create()
.setConnectionTimeToLive(portalConfig.connectionTimeToLive(), TimeUnit.MILLISECONDS)
.setConnectionManager(connectionManager)
.build();

restTemplate = new RestTemplate(httpMessageConverters.getConverters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public int connectionTimeToLive() {
return getIntProperty("api.connectionTimeToLive", -1);
}

public int connectPoolMaxTotal() {
return getIntProperty("api.pool.max.total", 20);
}

public int connectPoolMaxPerRoute() {
return getIntProperty("api.pool.max.per.route", 2);
}

public List<Organization> organizations() {

String organizations = getValue("organizations");
Expand Down

0 comments on commit f4a0236

Please sign in to comment.