private async Task <string> DoGetConfigAsync(GetConfigRequest request) { var responseMessage = await _clientFactory.DoRequestAsync(HttpMethod.Get, $"{GetBaseUrl()}{RequestPathValue.CONFIGS}", request.ToQueryString(), _options.DefaultTimeOut); switch (responseMessage.StatusCode) { case System.Net.HttpStatusCode.OK: var result = await responseMessage.Content.ReadAsStringAsync(); return(result); case System.Net.HttpStatusCode.NotFound: await _processor.SaveSnapshotAsync(request.DataId, request.Group, request.Tenant, null); return(null); case System.Net.HttpStatusCode.Forbidden: throw new NacosException(ConstValue.NO_RIGHT, $"Insufficient privilege."); default: throw new NacosException((int)responseMessage.StatusCode, responseMessage.StatusCode.ToString()); } }
private async Task <string> DoGetConfigAsync(GetConfigRequest request) { var item = 0; var urls = GetBaseUrls(); foreach (var url in urls) { var responseMessage = await _clientFactory.DoRequestAsync(HttpMethod.Get, $"{url}/nacos/v1/cs/configs", request.ToQueryString(), _options.DefaultTimeOut); switch (responseMessage.StatusCode) { case System.Net.HttpStatusCode.OK: //var stream = await responseMessage.Content.ReadAsStreamAsync(); //var result = await responseMessage.Content.ReadAsStringAsync(); return(await responseMessage.Content.ReadAsStringAsync()); //return ConvertJsonString(stream); case System.Net.HttpStatusCode.NotFound: await _processor.SaveSnapshotAsync(request.DataId, request.Group, request.Tenant, null); return(null); case System.Net.HttpStatusCode.Forbidden: throw new NacosException(ConstValue.NO_RIGHT, $"Insufficient privilege."); default: if (item == urls.Count - 1) { throw new NacosException((int)responseMessage.StatusCode, responseMessage.StatusCode.ToString()); } break; // } item++; } return(null); }
public async Task <bool> RegisterInstanceAsync(RegisterInstanceRequest request) { if (request == null) { throw new NacosException(ConstValue.CLIENT_INVALID_PARAM, "request param invalid"); } request.CheckParam(); var responseMessage = await _clientFactory.DoRequestAsync(HttpMethod.Post, $"{GetBaseUrl()}/nacos/v1/ns/instance", request.ToQueryString(), _options.TimeOut); switch (responseMessage.StatusCode) { case System.Net.HttpStatusCode.OK: var result = await responseMessage.Content.ReadAsStringAsync(); if (result.Equals("ok", StringComparison.OrdinalIgnoreCase)) { return(true); } else { _logger.LogWarning($"[client.RegisterInstance] server return {result} "); return(false); } default: _logger.LogWarning($"[client.RegisterInstance] Register an instance to service failed {responseMessage.StatusCode.ToString()}"); throw new NacosException((int)responseMessage.StatusCode, $"Register an instance to service failed {responseMessage.StatusCode.ToString()}"); } }