Skip to content

Commit

Permalink
feat: support portal restTemplate config ConnectionTimeToLive via Por…
Browse files Browse the repository at this point in the history
…talConfig `api.connectionTimeToLive` (#5120)
  • Loading branch information
larry4xie authored and nobodyiam committed Apr 9, 2024
1 parent c884de5 commit 287ec50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RestTemplate>, InitializingBean {
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public int readTimeout() {
return getIntProperty("api.readTimeout", 10000);
}

public int connectionTimeToLive() {
return getIntProperty("api.connectionTimeToLive", -1);
}

public List<Organization> organizations() {

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

0 comments on commit 287ec50

Please sign in to comment.