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);
                    }
                }
            }
        }
Exemple #2
0
        public void LogBrokerConnectionError_Logged()
        {
            var expectedMessage = "Error occurred connecting to the message broker(s).";

            _silverbackLogger.LogBrokerConnectionError(new AuthenticationException());

            _loggerSubstitute.Received(
                LogLevel.Error,
                typeof(AuthenticationException),
                expectedMessage,
                1017);
        }