Beispiel #1
0
        private static void SpecifyRetryStrategiesInCode()
        {
            // Define your retry strategy: retry 5 times, starting 1 second apart
            // and adding 2 seconds to the interval each retry.
            var retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));

            // Define your retry policy using the retry strategy and the Windows Azure storage
            // transient fault detection strategy.
            var retryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy);

            // Receive notifications about retries.
            retryPolicy.Retrying += (sender, args) =>
            {
                // Log details of the retry.
                var msg = String.Format("Retry - Count:{0}, Delay:{1}, Exception:{2}",
                    args.CurrentRetryCount, args.Delay, args.LastException);
                Trace.WriteLine(msg, "Information");
            };

            try
            {
                var queue = Queue.GetQueueReference("orders");

                // Do some work that may result in a transient fault.
                retryPolicy.ExecuteAction(
                  () =>
                  {
                      // Call a method that uses Windows Azure storage and which may
                      // throw a transient exception.
                      queue.CreateIfNotExists();
                  });
            }
            catch (Exception)
            {
                // All the retries failed.
            }
        }
 public ApiDownloaderService()
 {
     var retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
     _retryPolicy = new RetryPolicy<BGGTransientErrorDetectionStrategy>(retryStrategy);
 }
        public void Initialize()
        {
            var retryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
            var retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
            var namespaceManager = NamespaceManager.CreateFromConnectionString(settings.ConnectionString);

            this.settings.Topics.AsParallel().ForAll(topic =>
            {
                retryPolicy.ExecuteAction(() => CreateTopicIfNotExists(namespaceManager, topic));
                topic.Subscriptions.AsParallel().ForAll(subscription =>
                {
                    retryPolicy.ExecuteAction(() => CreateSubscriptionIfNotExists(namespaceManager, topic, subscription));
                    retryPolicy.ExecuteAction(() => UpdateRules(namespaceManager, this.settings.ConnectionString, topic, subscription));
                });
            });

            // Execute migration support actions only after all the previous ones have been completed.
            foreach (var topic in this.settings.Topics)
            {
                foreach (var action in topic.MigrationSupport)
                {
                    retryPolicy.ExecuteAction(() => UpdateSubscriptionIfExists(namespaceManager, this.settings.ConnectionString, topic, action));
                }
            }

            this.initialized = true;
        }