Example #1
0
 public void Log <TState>(
     LogLevel logLevel,
     EventId eventId,
     TState state,
     Exception exception,
     Func <TState, Exception, string> formatter) =>
 _logger.Log(logLevel, eventId, state, exception, formatter);
        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);
                    }
                }
            }
        }