コード例 #1
0
        public async Task <List <RegistryInformation> > FindServicesAsync(string name)
        {
            var queryResult = await _consul.Health.Service(name, tag : "", passingOnly : true);

            var instances = queryResult.Response.Select(serviceEntry => new RegistryInformation
            {
                Name    = serviceEntry.Service.Service,
                Address = serviceEntry.Service.Address,
                Port    = serviceEntry.Service.Port,
                Version = ServiceDiscoveryHelper.GetVersionFromStrings(serviceEntry.Service.Tags),
                Tags    = serviceEntry.Service.Tags ?? Enumerable.Empty <string>(),
                Id      = serviceEntry.Service.ID
            });

            return(instances.ToList());
        }
コード例 #2
0
        public async Task <List <RegistryInformation> > FindAllServicesAsync()
        {
            var queryResult = await _consul.Agent.Services();

            var instances = queryResult.Response.Select(serviceEntry => new RegistryInformation
            {
                Name    = serviceEntry.Value.Service,
                Id      = serviceEntry.Value.ID,
                Address = serviceEntry.Value.Address,
                Port    = serviceEntry.Value.Port,
                Version = ServiceDiscoveryHelper.GetVersionFromStrings(serviceEntry.Value.Tags),
                Tags    = serviceEntry.Value.Tags
            });

            return(instances.ToList());
        }