Ejemplo n.º 1
0
        public SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ILogger <SubscriptionReceiver> logger)
        {
            this.settings          = settings;
            this.topic             = topic;
            this.subscription      = subscription;
            this.processInParallel = processInParallel;
            this.logger            = logger;

            this.client = new SubscriptionClient(settings.ConnectionString, topic, subscription);
            if (this.processInParallel)
            {
                this.client.PrefetchCount = 18;
            }
            else
            {
                this.client.PrefetchCount = 14;
            }

            dynamicThrottling =
                new DynamicThrottling(
                    maxDegreeOfParallelism: 100,
                    minDegreeOfParallelism: 50,
                    penaltyAmount: 3,
                    workFailedPenaltyAmount: 5,
                    workCompletedParallelismGain: 1,
                    intervalForRestoringDegreeOfParallelism: 8000);

            receiveRetryPolicy = Policy.Handle <Exception>().WaitAndRetryAsync(3, (r) => TimeSpan.FromMilliseconds(900),//, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1));
                                                                               (ex, ts, attemps, cc) =>
            {
                this.dynamicThrottling.Penalize();
                logger.LogWarning($"An error occurred in attempt number {attemps} to receive a message from subscription {subscription}: {ex.Message}");
            });
        }
        public FileChunkController(CloudBlobContainer container)
        {
            this.container = container ?? throw new ArgumentNullException(nameof(container));

            // asyncronously handle transient exceptions by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policy = Policy.Handle <Exception>().WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));

            // syncronously handle transient file IO exceptions (excluding security exceptions) by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policyFile = Policy.Handle <Exception>(ex => !(ex is SecurityException || ex is UnauthorizedAccessException))
                         .WaitAndRetry(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));
        }
Ejemplo n.º 3
0
        public FileStitchController(ITopicClient topic, IHttpMessageFactory httpMessageFactory)
        {
            this.topic = topic ?? throw new ArgumentNullException(nameof(topic));
            this.httpMessageFactory = httpMessageFactory ?? throw new ArgumentNullException(nameof(httpMessageFactory));

            // asyncronously handle transient exceptions by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policy = Policy.Handle <Exception>().WaitAndRetryAsync(Constants.MAX_TRANSIENT_EXCEPTIONS, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));

            // syncronously handle transient file IO exceptions (excluding security exceptions) by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policyFile = Policy.Handle <Exception>(ex => !(ex is SecurityException || ex is UnauthorizedAccessException))
                         .WaitAndRetry(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));
        }
        public OnPremUploadDownloadController(ITopicClient topic, CloudBlobContainer container, IHttpMessageFactory messageFactory, IConfiguration config)
        {
            this.topic          = topic ?? throw new ArgumentNullException(nameof(topic));
            this.container      = container ?? throw new ArgumentNullException(nameof(container));
            this.messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory));
            this.config         = config ?? throw new ArgumentNullException(nameof(config));

            // asyncronously handle transient exceptions by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policy = Policy.Handle <Exception>().WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));

            // syncronously handle transient file IO exceptions (excluding security exceptions) by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policyFile = Policy.Handle <Exception>(ex => !(ex is SecurityException || ex is UnauthorizedAccessException))
                         .WaitAndRetry(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionSubscriptionReceiver"/> class,
        /// automatically creating the topic and subscription if they don't exist.
        /// </summary>
        public SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ILogger <SessionSubscriptionReceiver> logger)
        {
            this.settings     = settings;
            this.topic        = topic;
            this.subscription = subscription;
            this.requiresSequentialProcessing = requiresSequentialProcessing;
            this.logger = logger;

            client = new SubscriptionClient(settings.ConnectionString, topic, subscription, ReceiveMode.PeekLock, Microsoft.Azure.ServiceBus.RetryPolicy.Default);

            if (this.requiresSequentialProcessing)
            {
                this.client.PrefetchCount = 10;
            }
            else
            {
                this.client.PrefetchCount = 15;
            }

            this.dynamicThrottling =
                new DynamicThrottling(
                    maxDegreeOfParallelism: 160,
                    minDegreeOfParallelism: 30,
                    penaltyAmount: 3,
                    workFailedPenaltyAmount: 5,
                    workCompletedParallelismGain: 1,
                    intervalForRestoringDegreeOfParallelism: 10000);

            this.receiveRetryPolicy = Policy.Handle <Exception>()
                                      .WaitAndRetryAsync(10, retry => TimeSpan.FromSeconds(Math.Pow(2, retry)),
                                                         (ex, ts, attempt, context) =>
            {
                this.dynamicThrottling.Penalize();
                logger.LogWarning($"An error occurred in attempt number {attempt} to receive a message from subscription {subscription}: {ex.Message}");
            });
        }