/// <summary> /// Used: https://stackoverflow.com/a/40256772 /// </summary> /// <returns></returns> public async Task Discover(IEnumerable <string> serviceNames) { if (!_options.ResolveClientsOnStartup) { return; } try { foreach (var serviceName in serviceNames?.Distinct()) { _logger.LogInformation($"Resolving service: '{serviceName}'."); var serviceNameUri = ServiceFabricUriBuilder.Build(serviceName); var partitions = await _fabricClient.QueryManager.GetPartitionListAsync(serviceNameUri); foreach (var partition in partitions) { _logger.LogInformation($"Discovered service partition: '{partition.PartitionInformation.Kind}':'{partition.PartitionInformation.Id}'"); var key = partition.PartitionInformation.Kind switch { ServicePartitionKind.Singleton => ServicePartitionKey.Singleton, _ => throw new ArgumentOutOfRangeException($"Partitionkind: '{partition.PartitionInformation.Kind}' unknown."), }; try { var resolved = await _servicePartitionResolver.ResolveAsync(serviceNameUri, key, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), CancellationToken.None); foreach (var endpoint in resolved.Endpoints) { _logger.LogInformation($"Discovered service endpoint: '{endpoint.Address}'"); } } catch (Exception ex) { _logger.LogError($"Could not resolve service: '{serviceNameUri}'.", ex); } } } } catch (Exception ex) { _logger.LogError(ex.Message, ex); } }
public async Task <List <Service> > Get() { var serviceNameUri = ServiceFabricUriBuilder.Build(_servicename); var services = new List <Service>(); try { var service = await _servicePartitionResolver.ResolveAsync(serviceNameUri, ServicePartitionKey.Singleton, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), CancellationToken.None); services.Add(BuildService(service)); } catch (Exception ex) { _logger.LogError($"Could not resolve service: '{serviceNameUri}'.", ex); } return(services); }