Пример #1
0
        public IConfigurationProvider Build(IConfigurationBuilder builder)
        {
            var provider = new ConsulConfigurationProvider(Config);

            ObserverManager.Attach(provider, Config);
            return(provider);
        }
        private async Task QueryConsulAsync()
        {
            using (var client = new ConsulClient(options =>
            {
                options.WaitTime = ObserverManager.Configuration.ClientConfiguration.WaitTime;
                options.Token = ObserverManager.Configuration.ClientConfiguration.Token;
                options.Datacenter = ObserverManager.Configuration.ClientConfiguration.Datacenter;
                options.Address = ObserverManager.Configuration.ClientConfiguration.Address;
            }))
            {
                var result = await client.KV.List(ObserverManager.Configuration.QueryOptions.RootFolder, new QueryOptions
                {
                    Token      = ObserverManager.Configuration.ClientConfiguration.Token,
                    Datacenter = ObserverManager.Configuration.ClientConfiguration.Datacenter,
                    WaitIndex  = LastIndex,
                    WaitTime   = HostedServiceOptions.BlockingQueryWait
                }, CancellationTokenSource.Token);

                if (result.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return;
                }
                if (result.LastIndex > LastIndex)
                {
                    LastIndex = result.LastIndex;
                    ObserverManager.Notify(result.Response.ToList(), Logger);
                }
            }
        }