Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support portal restTemplate Client connection pool config #5200

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Apollo 2.3.0
* [Fix the role permission deletion issue when appid contains '_'](https://github.com/apolloconfig/apollo/pull/5150)
* [fix: -XX:HeapDumpPath doesn't ready when meet OOM](https://github.com/apolloconfig/apollo/pull/5157)
* [Fix the error occurred when using configuration retention feature](https://github.com/apolloconfig/apollo/pull/5162)
* [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/14?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);
youngzil marked this conversation as resolved.
Show resolved Hide resolved
}

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

public List<Organization> organizations() {

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