Esempio n. 1
0
        public async Task <List <string> > ListServiceAsync()
        {
            ListServicesRequest request = new ListServicesRequest {
                PageNo = 1, PageSize = int.MaxValue
            };

            var responseMessage = await _clientFactory.DoRequestAsync(HttpMethod.Get, $"{GetBaseUrl()}/nacos/v1/ns/service/list", request.ToQueryString(), _options.TimeOut);

            switch (responseMessage.StatusCode)
            {
            case System.Net.HttpStatusCode.OK:
                var result = await responseMessage.Content.ReadAsStringAsync();

                var obj = result.JsonDeserialize <ListServicesResult>();
                return(obj.Doms);

            default:
                _logger.LogWarning($"[client.GetService] Query a service failed {responseMessage.StatusCode.ToString()}");
                throw new NacosException((int)responseMessage.StatusCode, $"Query a service failed {responseMessage.StatusCode.ToString()}");
            }
        }
Esempio n. 2
0
        public async Task <ListServicesResult> ListServicesAsync(ListServicesRequest request)
        {
            if (request == null)
            {
                throw new NacosException(ConstValue.CLIENT_INVALID_PARAM, "request param invalid");
            }

            request.CheckParam();

            var responseMessage = await _clientFactory.DoRequestAsync(HttpMethod.Get, $"{GetBaseUrl()}/nacos/v1/ns/service/list", request.ToQueryString(), _options.TimeOut);

            switch (responseMessage.StatusCode)
            {
            case System.Net.HttpStatusCode.OK:
                var result = await responseMessage.Content.ReadAsStringAsync();

                var obj = result.JsonDeserialize <ListServicesResult>();
                return(obj);

            default:
                _logger.LogWarning($"[client.ListServices] Query service list failed {responseMessage.StatusCode.ToString()}");
                throw new NacosException((int)responseMessage.StatusCode, $"Query service list failed {responseMessage.StatusCode.ToString()}");
            }
        }