HttpGet:add http time out
This commit is contained in:
parent
e138b8d5fc
commit
8dd788de6a
|
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
|
@ -46,6 +47,9 @@ import static org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.C
|
|||
*/
|
||||
public class DiscoveryRestServiceClient implements Runnable {
|
||||
private static final ILog logger = LogManager.getLogger(DiscoveryRestServiceClient.class);
|
||||
private static final int HTTP_CONNECT_TIMEOUT = 2000;
|
||||
private static final int HTTP_CONNECTION_REQUEST_TIMEOUT = 1000;
|
||||
private static final int HTTP_SOCKET_TIMEOUT = 2000;
|
||||
private String[] serverList;
|
||||
private volatile int selectedServer = -1;
|
||||
|
||||
|
|
@ -133,7 +137,11 @@ public class DiscoveryRestServiceClient implements Runnable {
|
|||
return null;
|
||||
}
|
||||
HttpGet httpGet = new HttpGet("http://" + serverList[selectedServer] + Config.Collector.DISCOVERY_SERVICE_NAME);
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(HTTP_CONNECT_TIMEOUT)
|
||||
.setConnectionRequestTimeout(HTTP_CONNECTION_REQUEST_TIMEOUT)
|
||||
.setSocketTimeout(HTTP_SOCKET_TIMEOUT).build();
|
||||
httpGet.setConfig(requestConfig);
|
||||
return httpGet;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue