public IActionResult Index([FromServices] IDiscoveryClient discoveryClient) { var omsUrl = discoveryClient.GetInstances("ORDERMANAGER")?.FirstOrDefault()?.Uri?.ToString() ?? "http://localhost:8080"; var mdsUrl = discoveryClient.GetInstances("MDS")?.FirstOrDefault()?.Uri?.ToString() ?? "http://localhost:53809"; ViewBag.OMS = omsUrl.MatchCurrentScheme(HttpContext); ViewBag.MDS = mdsUrl.MatchCurrentScheme(HttpContext); return(View()); }
public IActionResult Index([FromServices] IDiscoveryClient discoveryClient) { var omsUrl = discoveryClient.GetInstances("ORDERMANAGER")?.FirstOrDefault()?.Uri?.ToString() ?? "http://localhost:8080"; omsUrl = omsUrl.Replace("https://", "http://"); // need to force http due to self signed cert ViewBag.OMS = omsUrl; ViewBag.MDS = discoveryClient.GetInstances("MDS")?.FirstOrDefault()?.Uri?.ToString() ?? "http://localhost:53809"; return(View()); }
private String LookupUrlForExchange(String symbol) { var serviceInstances = _discoveryClient.GetInstances("Exchange_" + symbol); String url = serviceInstances[0].Uri.ToString().Trim('/'); return(url); }
public virtual Uri LookupService(Uri current) { _logger?.LogDebug("LookupService({0})", current.ToString()); if (!current.IsDefaultPort) { return(current); } var instances = _client.GetInstances(current.Host); if (instances.Count > 0) { var index = _random.Next(instances.Count); var result = instances[index].Uri; _logger?.LogDebug("Resolved {url} to {service}", current.Host, result.Host); current = new Uri(result, current.PathAndQuery); } else { _logger?.LogWarning("Attempted to resolve service for {url} but found 0 instances", current.Host); } _logger?.LogDebug("LookupService() returning {0} ", current.ToString()); return(current); }
public IActionResult Index() { var services = _discoveryClient.Services.Select(service => new { ServiceName = service, Instances = _discoveryClient.GetInstances(service) } ); return(Json(services)); }
public Task <List <Service> > Get() { var services = new List <Service>(); var instances = _client.GetInstances(_serviceName); if (instances != null && instances.Any()) { services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port, i.Uri.Scheme), "", "", new List <string>()))); } return(Task.FromResult(services)); }
public HttpClientProvider(IDiscoveryClient discoveryClient, IOptions <HttpClientOptions> options, ILogger <HttpClientProvider> logger) { this._logger = logger; _logger.LogDebug("Building HttpClientProvider"); if (discoveryClient != null) { Console.Write(" with discoveryClient"); } if (options.Value != null) { Console.Write($" with options {options.Value}"); } this._discoveryClient = discoveryClient; _logger.LogDebug("******** services: "); foreach (var service in discoveryClient.Services) { _logger.LogDebug($"{service}, "); } _logger.LogDebug("******** fare-service: "); foreach (var service in discoveryClient.GetInstances("fare-service")) { _logger.LogDebug($"{service.ServiceId}:{service.Uri}, "); } _logger.LogDebug("******** FARE-SERVICE: "); foreach (var service in discoveryClient.GetInstances("FARE-SERVICE")) { _logger.LogDebug($"{service.ServiceId}:{service.Uri}, "); } this.configure(options.Value); }
public IActionResult ServiceDiscovery([FromServices] IDiscoveryClient discoveryClient) { var services = discoveryClient.Services .Select(serviceName => new DiscoveredService { Name = serviceName, Urls = discoveryClient.GetInstances(serviceName).Select(x => x.Uri.ToString()).ToList() }) .ToList(); var uri = new Uri(_app.Value.CF_Api); var systemDomain = Regex.Replace(uri.Host, @"^.+?\.", string.Empty); ViewBag.MetricsUrl = $"https://metrics.{systemDomain}/apps/{_app.Value.Application_Id}/dashboard"; return(View("Eureka", services)); }
public async Task <IActionResult> Weather() { var apiGatewayInstances = discoClient.GetInstances("api-gateway"); var apiGatewayUri = apiGatewayInstances.First().Uri; using (var client = new HttpClient()) { // 调用计算服务,计算两个整数的和与差 const int x = 124, y = 134; var sumResponse = await client.GetAsync($"{apiGatewayUri}calc/api/calculation/add/{x}/{y}"); sumResponse.EnsureSuccessStatusCode(); var sumResult = await sumResponse.Content.ReadAsStringAsync(); ViewData["sum"] = $"x + y = {sumResult}"; var subResponse = await client.GetAsync($"{apiGatewayUri}calc/api/calculation/sub/{x}/{y}"); subResponse.EnsureSuccessStatusCode(); var subResult = await subResponse.Content.ReadAsStringAsync(); ViewData["sub"] = $"x - y = {subResult}"; // 调用天气服务,计算大连和广州的平均气温标准差 var stddevShenyangResponse = await client.GetAsync($"{apiGatewayUri}weather/api/weather/stddev/shenyang"); stddevShenyangResponse.EnsureSuccessStatusCode(); var stddevShenyangResult = await stddevShenyangResponse.Content.ReadAsStringAsync(); ViewData["stddev_sy"] = $"沈阳:{stddevShenyangResult}"; var stddevGuangzhouResponse = await client.GetAsync($"{apiGatewayUri}weather/api/weather/stddev/guangzhou"); stddevGuangzhouResponse.EnsureSuccessStatusCode(); var stddevGuangzhouResult = await stddevGuangzhouResponse.Content.ReadAsStringAsync(); ViewData["stddev_gz"] = $"广州:{stddevGuangzhouResult}"; // 查看Calc服务的App名称 var calcAppNameResponse = await client.GetAsync($"{apiGatewayUri}calc/api/calculation/info"); calcAppNameResponse.EnsureSuccessStatusCode(); var calcAppNameResult = await calcAppNameResponse.Content.ReadAsStringAsync(); ViewData["calc_app_name"] = $"计算服务名称:{calcAppNameResult}"; } return(View()); }
/// <summary> /// 获取服务地址 /// </summary> /// <param name="client"></param> /// <param name="current"></param> /// <returns></returns> private static Uri LookupService(this IDiscoveryClient client, Uri current) { if (!current.IsDefaultPort) { return(current); } var instances = client.GetInstances(current.Host); if (instances.Count > 0) { int indx = new Random().Next(instances.Count); return(new Uri(instances[indx].Uri, current.PathAndQuery)); } return(current); }
internal protected override Uri LookupService(Uri current) { if (!current.IsDefaultPort) { return(current); } var instances = _client.GetInstances(current.Host); if (instances.Count > 0) { int indx = _random.Next(instances.Count); return(new Uri(instances[indx].Uri, current.PathAndQuery)); } return(current); }
internal protected override Uri LookupService(Uri current) { _logger?.LogDebug("LookupService({0})", current.ToString()); if (!current.IsDefaultPort) { return(current); } var instances = _client.GetInstances(current.Host); if (instances.Count > 0) { int indx = _random.Next(instances.Count); current = new Uri(instances[indx].Uri, current.PathAndQuery); } _logger?.LogDebug("LookupService() returning {0} ", current.ToString()); return(current); }
internal IEnumerable <IServiceInstance> GetConfigServerInstances() { var attempts = 0; var backOff = _settings.RetryInitialInterval; IEnumerable <IServiceInstance> instances; do { try { _logger.LogDebug("Locating configserver {serviceId} via discovery", _settings.DiscoveryServiceId); instances = _discoveryClient.GetInstances(_settings.DiscoveryServiceId); } catch (Exception e) { _logger.LogError(e, "Exception invoking GetInstances() during config server lookup"); instances = Enumerable.Empty <IServiceInstance>(); } if (!_settings.RetryEnabled || instances.Any()) { break; } attempts++; if (attempts <= _settings.RetryAttempts) { Thread.CurrentThread.Join(backOff); var nextBackoff = (int)(backOff * _settings.RetryMultiplier); backOff = Math.Min(nextBackoff, _settings.RetryMaxInterval); } else { break; } }while (true); return(instances); }
public IList <IServiceInstance> GetServiceInstances(string serviceId) { return(_discoveryClient.GetInstances(serviceId).Select(s => new SteeltoeServiceInstance(s)).ToList <IServiceInstance>()); }
// Enable this for security //[Authorize(Policy = "read.fortunes")] /// <summary> /// Services Page. /// </summary> /// <returns></returns> public async Task <IActionResult> Services() { _logger?.LogDebug("RandomFortune"); ViewData["FortuneUrl"] = _fortunesConfig.Value.RandomFortuneURL; var fortune = await _fortunes.RandomFortuneAsync(); var _fortuneHistory = RedisCacheStore?.GetString("FortuneHistory"); if (!string.IsNullOrEmpty(_fortuneHistory)) { fortunes = JsonConvert.DeserializeObject <List <string> >(_fortuneHistory); } fortunes.Insert(0, fortune.Text); if (fortunes.Count > 10) { fortunes.RemoveAt(10); } string fortuneoutput = JsonConvert.SerializeObject(fortunes); RedisCacheStore?.SetString("FortuneHistory", fortuneoutput); HttpContext.Session.SetString("MyFortune", fortune.Text); var _appInstCount = RedisCacheStore?.GetString("AppInstance"); if (!string.IsNullOrEmpty(_appInstCount)) { _logger?.LogInformation($"App Session Data: {_appInstCount}"); appInstCount = JsonConvert.DeserializeObject <SortedList <int, int> >(_appInstCount); } var _srvInstCount = RedisCacheStore?.GetString("SrvInstance"); if (!string.IsNullOrEmpty(_srvInstCount)) { _logger?.LogInformation($"Servlet Session Data: {_srvInstCount}"); srvInstCount = JsonConvert.DeserializeObject <SortedList <int, int> >(_srvInstCount); } var _count2 = srvInstCount.GetValueOrDefault(fortune.InstanceIndex, 0); srvInstCount[fortune.InstanceIndex] = ++_count2; string output2 = JsonConvert.SerializeObject(srvInstCount); RedisCacheStore?.SetString("SrvInstance", output2); ViewData["MyFortune"] = fortune.Text; ViewData["FortuneIndex"] = $"{fortune.InstanceIndex}"; ViewData["FortuneDiscoveryUrl"] = discoveryClient.GetInstances("fortuneService")?[fortune.InstanceIndex]?.Uri?.ToString(); return(View(new CloudFoundryViewModel( CloudFoundryApplication == null ? new CloudFoundryApplicationOptions() : CloudFoundryApplication, CloudFoundryServices == null ? new CloudFoundryServicesOptions() : CloudFoundryServices, IConfigServerData.Value, discoveryClient, appInstCount, srvInstCount, fortunes, connects))); }