private async Task <QueryResult <KVPair[]> > GetKvPairs( string key, CancellationToken cancellationToken, QueryOptions queryOptions = null) { using (IConsulClient consulClient = _consulClientFactory.Create()) { QueryResult <KVPair[]> result = await consulClient .KV .List(key, queryOptions, cancellationToken) .ConfigureAwait(false); switch (result.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.NotFound: return(result); default: throw new Exception( $"Error loading configuration from consul. Status code: {result.StatusCode}."); } } }
private async Task <QueryResult <KVPair> > GetKVPair(QueryOptions queryOptions = null) { using (IConsulClient consulClient = _consulClientFactory.Create()) { QueryResult <KVPair> result = await consulClient.KV.Get(_source.Key, queryOptions, _source.CancellationToken); switch (result.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.NotFound: return(result); default: throw new Exception($"Error loading configuration from consul. Status code: {result.StatusCode}."); } } }
private async Task <QueryResult <KVPair[]> > GetKvPairs(bool waitForChange, CancellationToken cancellationToken) { using var consulClient = _consulClientFactory.Create(); var queryOptions = new QueryOptions { WaitTime = _source.PollWaitTime, WaitIndex = waitForChange ? _lastIndex : 0 }; var result = await consulClient .KV .List(_source.Key, queryOptions, cancellationToken) .ConfigureAwait(false); return(result.StatusCode switch { HttpStatusCode.OK => result, HttpStatusCode.NotFound => result, _ => throw new Exception($"Error loading configuration from consul. Status code: {result.StatusCode}.") });