private async Task EnterRoutes() { if (_routes != null && _routes.Length > 0) { return; } Action <string[]> action = null; if (_configInfo.EnableChildrenMonitor) { var watcher = new ChildrenMonitorWatcher(_consul, _manager, _configInfo.MqttRoutePath, async(oldChildrens, newChildrens) => await ChildrenChange(oldChildrens, newChildrens), (result) => ConvertPaths(result).Result); action = currentData => watcher.SetCurrentData(currentData); } if (_consul.KV.Keys(_configInfo.MqttRoutePath).Result.Response?.Count() > 0) { var result = await _consul.GetChildrenAsync(_configInfo.MqttRoutePath); var keys = await _consul.KV.Keys(_configInfo.MqttRoutePath); var childrens = result; action?.Invoke(ConvertPaths(childrens).Result.Select(key => $"{_configInfo.MqttRoutePath}{key}").ToArray()); _routes = await GetRoutes(keys.Response); } else { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) { _logger.LogWarning($"无法获取路由信息,因为节点:{_configInfo.MqttRoutePath},不存在。"); } _routes = new MqttServiceRoute[0]; } }
private async Task EnterServiceCommands() { if (_serviceCommands != null) { return; } var watcher = new ChildrenMonitorWatcher(_consul, _manager, _configInfo.CommandPath, async(oldChildrens, newChildrens) => await ChildrenChange(oldChildrens, newChildrens)); if (_consul.KV.Keys(_configInfo.CommandPath).Result.Response?.Count() > 0) { var result = await _consul.GetChildrenAsync(_configInfo.CommandPath); var keys = await _consul.KV.Keys(_configInfo.CommandPath); var childrens = result; watcher.SetCurrentData(childrens); _serviceCommands = await GetServiceCommands(keys.Response); } else { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) { _logger.LogWarning($"无法获取服务命令信息,因为节点:{_configInfo.CommandPath},不存在。"); } _serviceCommands = new ServiceCommandDescriptor[0]; } }
private async Task EnterCaches() { if (_serviceCaches != null && _serviceCaches.Length > 0) { return; } var watcher = new ChildrenMonitorWatcher(_consul, _manager, _configInfo.CachePath, async(oldChildrens, newChildrens) => await ChildrenChange(oldChildrens, newChildrens), (result) => ConvertPaths(result).Result); if (_consul.KV.Keys(_configInfo.CachePath).Result.Response?.Count() > 0) { var result = await _consul.GetChildrenAsync(_configInfo.CachePath); var keys = await _consul.KV.Keys(_configInfo.CachePath); var childrens = result; watcher.SetCurrentData(ConvertPaths(childrens).Result.Select(key => $"{_configInfo.CachePath}{key}").ToArray()); _serviceCaches = await GetCaches(keys.Response); } else { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) { _logger.LogWarning($"无法获取缓存信息,因为节点:{_configInfo.CachePath},不存在。"); } _serviceCaches = new ServiceCache[0]; } }
private async Task EnterRoutes() { if (_routes != null) { return; } var watcher = new ChildrenMonitorWatcher(_consul, _manager, _configInfo.RoutePath, async(oldChildrens, newChildrens) => await ChildrenChange(oldChildrens, newChildrens), (result) => ConvertPaths(result).Result); if (_consul.KV.Keys(_configInfo.RoutePath).Result.Response?.Count() > 0) { var result = await _consul.GetChildrenAsync(_configInfo.RoutePath); var keys = await _consul.KV.Keys(_configInfo.RoutePath); var childrens = result; watcher.SetCurrentData(childrens); _routes = await GetRoutes(keys.Response); } else { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) { _logger.LogWarning($"无法获取路由信息,因为节点:{_configInfo.RoutePath},不存在。"); } _routes = new ServiceRoute[0]; } }
protected override async Task ProcessImpl() { RegisterWatch(this); var result = await _client.GetChildrenAsync(_path); if (result != null) { var convertResult = _func.Invoke(result).Select(key => $"{_path}{key}").ToArray(); _action(_currentData, convertResult); this.SetCurrentData(convertResult); } }
protected override async Task ProcessImpl() { Func <ChildrenMonitorWatcher> getWatcher = () => new ChildrenMonitorWatcher(_client, _manager, _path, _action); var watcher = getWatcher(); RegisterWatch(watcher); var result = await _client.GetChildrenAsync(_path); if (result != null) { _action(_currentData, result); watcher.SetCurrentData(result); } }
private async Task EnterSubscribers() { if (_subscribers != null) { return; } if (_consul.KV.Keys(_configInfo.SubscriberPath).Result.Response?.Count() > 0) { var result = await _consul.GetChildrenAsync(_configInfo.SubscriberPath); var keys = await _consul.KV.Keys(_configInfo.SubscriberPath); var childrens = result; _subscribers = await GetSubscribers(keys.Response); } else { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) { _logger.LogWarning($"无法获取订阅者信息,因为节点:{_configInfo.SubscriberPath},不存在。"); } _subscribers = new ServiceSubscriber[0]; } }