示例#1
0
        private void PostConfiguration(ServiceBusOptions serviceBusConfig)
        {
            if (serviceBusConfig == null)
            {
                return;
            }

            if (serviceBusConfig.RetryPolicy == null)
            {
                serviceBusConfig.Policy = RetryPolicy.Default;
            }
            else if (serviceBusConfig.RetryPolicy.MaximumRetryCount == 0 &&
                     serviceBusConfig.RetryPolicy.MaximumBackoffInSeconds == 0 &&
                     serviceBusConfig.RetryPolicy.MinimumBackoffInSeconds == 0 &&
                     serviceBusConfig.RetryPolicy.DeltaBackoffInSeconds == 0)
            {
                serviceBusConfig.Policy = RetryPolicy.NoRetry;
            }
            else
            {
                var retryExponential = new RetryExponential(TimeSpan.FromSeconds(serviceBusConfig.RetryPolicy.MinimumBackoffInSeconds),
                                                            TimeSpan.FromSeconds(serviceBusConfig.RetryPolicy.MaximumBackoffInSeconds),
                                                            TimeSpan.FromSeconds(serviceBusConfig.RetryPolicy.DeltaBackoffInSeconds),
                                                            serviceBusConfig.RetryPolicy.MaximumRetryCount);
                serviceBusConfig.Policy = retryExponential;
            }
        }
        private void PostConfiguration(ServiceBusOptions serviceBusConfig)
        {
            if (!Enum.IsDefined(typeof(TransportType), serviceBusConfig.TransportType))
            {
                throw new ArgumentOutOfRangeException(nameof(serviceBusConfig.TransportType), $"Value specified was not a valid {typeof(TransportType).FullName}.");
            }

            if (!Enum.IsDefined(typeof(ReceiveMode), serviceBusConfig.ReceiveMode))
            {
                throw new ArgumentOutOfRangeException(nameof(serviceBusConfig.ReceiveMode), $"Value specified was not a valid {typeof(ReceiveMode).FullName}.");
            }

            if (serviceBusConfig.RetryPolicy == null)
            {
                serviceBusConfig.Policy = RetryPolicy.Default;
            }
            else if (serviceBusConfig.RetryPolicy.MaximumRetryCount == 0 && serviceBusConfig.RetryPolicy.MaximumBackoff == 0 && serviceBusConfig.RetryPolicy.MinimumBackoff == 0)
            {
                serviceBusConfig.Policy = RetryPolicy.NoRetry;
            }
            else
            {
                var retryExponential = new RetryExponential(TimeSpan.FromSeconds(serviceBusConfig.RetryPolicy.MinimumBackoff),
                                                            TimeSpan.FromSeconds(serviceBusConfig.RetryPolicy.MaximumBackoff),
                                                            serviceBusConfig.RetryPolicy.MaximumRetryCount);
                serviceBusConfig.Policy = retryExponential;
            }
        }
示例#3
0
        internal ServiceBusOptions Build()
        {
            var options = new ServiceBusOptions();

            if (_azureServiceBusSectionName != null && _serviceBusOptionsSection.Exists())
            {
                options = _serviceBusOptionsSection.Get <ServiceBusOptions>();
                PostConfiguration(options);
            }

            if (string.IsNullOrWhiteSpace(_connectionString) && string.IsNullOrWhiteSpace(options.ConnectionString))
            {
                throw new Exception("A connection string is required.");
            }

            if (!string.IsNullOrWhiteSpace(_connectionString))
            {
                options.ConnectionString = _connectionString;
            }

            if (_retryPolicy != RetryPolicy.Default)
            {
                options.Policy = _retryPolicy;
            }

            if (!(_tokenProvider is NullTokenProvider))
            {
                var connStringBuilder = new ServiceBusConnectionStringBuilder(options.ConnectionString);
                if (string.IsNullOrWhiteSpace(connStringBuilder.SasToken) && string.IsNullOrWhiteSpace(connStringBuilder.SasKey))
                {
                    options.TokenProvider = _tokenProvider;
                }
            }

            if (_maxConcurrentCalls != _defaultMaxConcurrentCalls)
            {
                options.MaxConcurrentCalls = _maxConcurrentCalls;
            }

            if (_prefetchCount != _defaultPrefetchCount)
            {
                options.PrefetchCount = _prefetchCount;
            }

            Services.AddSingleton(options);

            return(options);
        }