Commit 0cddf9cf by Jason Song

use RestTemplateFactory to create rest template, which will respect the…

use RestTemplateFactory to create rest template, which will respect the api.connectTimeout and api.readTimeout settings in PortalConfig
parent 8db5e264
...@@ -32,7 +32,6 @@ import javax.annotation.PostConstruct; ...@@ -32,7 +32,6 @@ import javax.annotation.PostConstruct;
@Component @Component
public class AdminServiceAddressLocator { public class AdminServiceAddressLocator {
private static final int DEFAULT_TIMEOUT_MS = 1000;
private static final long NORMAL_REFRESH_INTERVAL = 5 * 60 * 1000; private static final long NORMAL_REFRESH_INTERVAL = 5 * 60 * 1000;
private static final long OFFLINE_REFRESH_INTERVAL = 10 * 1000; private static final long OFFLINE_REFRESH_INTERVAL = 10 * 1000;
private static final int RETRY_TIMES = 3; private static final int RETRY_TIMES = 3;
...@@ -48,24 +47,15 @@ public class AdminServiceAddressLocator { ...@@ -48,24 +47,15 @@ public class AdminServiceAddressLocator {
private HttpMessageConverters httpMessageConverters; private HttpMessageConverters httpMessageConverters;
@Autowired @Autowired
private PortalSettings portalSettings; private PortalSettings portalSettings;
@Autowired
private RestTemplateFactory restTemplateFactory;
@PostConstruct @PostConstruct
public void init() { public void init() {
allEnvs = portalSettings.getAllEnvs(); allEnvs = portalSettings.getAllEnvs();
//init restTemplate //init restTemplate
restTemplate = new RestTemplate(httpMessageConverters.getConverters()); restTemplate = restTemplateFactory.getObject();
if (restTemplate.getRequestFactory() instanceof SimpleClientHttpRequestFactory) {
SimpleClientHttpRequestFactory rf =
(SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(DEFAULT_TIMEOUT_MS);
rf.setConnectTimeout(DEFAULT_TIMEOUT_MS);
} else if (restTemplate.getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) {
HttpComponentsClientHttpRequestFactory rf =
(HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(DEFAULT_TIMEOUT_MS);
rf.setConnectTimeout(DEFAULT_TIMEOUT_MS);
}
refreshServiceAddressService = refreshServiceAddressService =
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("ServiceLocator", false)); Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("ServiceLocator", false));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment