private async Task ConnectAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { await _brokerCollection.ConnectAsync().ConfigureAwait(false); break; } catch (Exception ex) { _logger.LogBrokerConnectionError(ex); if (!_connectionOptions.RetryOnFailure) { break; } if (_connectionOptions.Mode == BrokerConnectionMode.Startup) { Thread.Sleep(_connectionOptions.RetryInterval); } else { await Task.Delay(_connectionOptions.RetryInterval, stoppingToken).ConfigureAwait(false); } } } }
private async Task ConnectAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { await _brokerCollection.ConnectAsync().ConfigureAwait(false); break; } catch (Exception ex) { _logger.Log( _connectionOptions.RetryOnFailure ? LogLevel.Error : LogLevel.Critical, IntegrationEventIds.BrokerConnectionError, ex, "Error occurred connecting to the message broker(s)."); if (!_connectionOptions.RetryOnFailure) { break; } if (_connectionOptions.Mode == BrokerConnectionMode.Startup) { Thread.Sleep(_connectionOptions.RetryInterval); } else { await Task.Delay(_connectionOptions.RetryInterval, stoppingToken).ConfigureAwait(false); } } } }