public async Task Register() { if (!_registered) { await RabbitHttpClient.CreateVHostAndConfigs(_config.ConnConfig); await _consumerManager.Register(); _registered = true; } }
private async Task ScaleListeners() { _logger?.LogDebug($"\r\n[RabbitLight] Start scalling"); int expected = _config.ConnConfig.MinChannels; if (_config.ConnConfig.ScallingThreshold.HasValue) { // try catch in case the initial queues were killed try { var tasks = _consumers.Select(x => RabbitHttpClient.GetMessageCount(_config.ConnConfig, x.Queue.Name)); var requests = await Task.WhenAll(tasks); var messageCount = requests.Sum(); expected += (int)Math.Ceiling((double)messageCount / _config.ConnConfig.ScallingThreshold.Value); } catch { } } _logger?.LogDebug($"[RabbitLight] Expected channels: {expected}"); expected = expected > _config.ConnConfig.MaxChannels ? _config.ConnConfig.MaxChannels : expected; var diff = expected - _connPool.TotalChannels; _logger?.LogDebug($"[RabbitLight] Total channels: {_connPool.TotalChannels}"); _logger?.LogDebug($"[RabbitLight] Diff channels: {diff}"); if (diff != 0) { _logger?.LogDebug($"[RabbitLight] Scalling ({_connPool.TotalChannels} -> {expected})"); } if (diff > 0) { await RegisterListeners(diff); } else if (diff < 0) { await _connPool.DeleteChannels(-diff); } _logger?.LogDebug($"[RabbitLight] End scalling\r\n"); }
public void StartMonitor() { Helpers.Monitor.Run(() => RabbitHttpClient.CreateVHostAndConfigs(_config.ConnConfig), _config.ConnConfig.MonitoringInterval, _config.ConnConfig.MonitoringInterval, _cts.Token, ex => Task.Run(() => _logger?.LogError(ex, "[RabbitLight] Error while ensuring VHost and configs"))); }