protected T DoRequest <T>(object requestContent) { int retryCount = -1; ExponentialBackOff backOff = null; do { retryCount++; if (retryCount > 0) { // 等待一段时间再发起重试 if (backOff == null) { backOff = new ExponentialBackOff(250, 2.0, disConfig.GetBackOffMaxIntervalMs(), ExponentialBackOff.DEFAULT_MAX_ELAPSED_TIME); } backOff.backOff(backOff.getNextBackOff()); } try { requestObs.Headers.Remove(HttpHeaderKeys.Authorization); requestObs.Headers.Remove(HttpHeaderKeys.SdkData); requestObs.Headers.Remove(HttpHeaderKeys.SdkShaContent); requestObs.Headers.Remove(HttpHeaderKeys.HostHeader); // 每次重传需要重新签名 requestObs = SignUtil.Sign(requestObs, disConfig.GetAK(), disConfig.GetSK(), disConfig.GetRegion()); return(DoRequest <T>(requestObs, requestContent)); } catch (Exception t) { String errorMsg = t.Message; int statusCode = int.Parse(errorMsg.Split('\n')[0]); // 如果不是可以重试的异常 或者 已达到重试次数,则直接抛出异常 if (!Utils.Utils.IsRetriableSendException(statusCode) || retryCount >= disConfig.GetExceptionRetries()) { throw new Exception(errorMsg.Substring(statusCode.ToString().Length + 1), t); } logger.WarnFormat("Find Retriable Exception {0}, url [{1} {2}], currRetryCount is {3}", errorMsg.Replace("\r\n", ""), requestObs.HttpMethod, requestObs.Endpoint.Host.Trim('/') + requestObs.ResourcePath, retryCount); } } while (retryCount < disConfig.GetExceptionRetries()); return(default(T)); }
public DISIngestionClient(string disConfigFile) { _disConfig = DISConfig.BuildConfig(disConfigFile); _credentials = new BasicCredentials(_disConfig.GetAK(), _disConfig.GetSK()); _region = _disConfig.GetRegion(); }
public DISIngestionClient() { _disConfig = DISConfig.buildDefaultConfig(); _credentials = new BasicCredentials(_disConfig.GetAK(), _disConfig.GetSK()); _region = _disConfig.GetRegion(); }