public static async Task Insert(CloudTable table) { CustomerEntity customer1 = new CustomerEntity("Harp", "Walters") { Email = "*****@*****.**", PhoneNumber = "425-555-0101" }; CustomerEntity customer2 = new CustomerEntity("Harp", "Ben") { Email = "*****@*****.**", PhoneNumber = "425-555-0102" }; TableBatchOperation batchOperation = new TableBatchOperation(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(customer1); batchOperation.Insert(customer1); batchOperation.Insert(customer2); // Execute the insert operation. Incremental retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)); ExponentialBackoff retryStrategy2=new ExponentialBackoff(5,TimeSpan.FromSeconds(1),TimeSpan.FromSeconds(5),TimeSpan.FromSeconds(2)); TimeSpan back = TimeSpan.FromSeconds(31); // Define your retry policy using the retry strategy and the Azure storage // transient fault detection strategy. RetryPolicy<StorageTransientErrorDetectionStrategy> retryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy); RetryPolicy<StorageTransientErrorDetectionStrategy> r = new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy2); // Receive notifications about retries. retryPolicy.Retrying += (sender, args) => { Console.WriteLine("Information"); // Log details of the retry. var msg = String.Format("Retry - Count:{0}, Delay:{1}, Exception:{2}", args.CurrentRetryCount, args.Delay, args.LastException); Console.WriteLine(msg, "Information"); }; try { // Do some work that may result in a transient fault. await retryPolicy.ExecuteAsync( () => table.ExecuteBatchAsync(batchOperation)); } catch (Exception e) { var z = e; } Console.ReadLine(); /* // Create a new customer entity. CustomerEntity customer1 = new CustomerEntity("Harp", "Walters") { Email = "*****@*****.**", PhoneNumber = "425-555-0101" }; CustomerEntity customer2 = new CustomerEntity("Harp", "Ben") { Email = "*****@*****.**", PhoneNumber = "425-555-0102" }; TableBatchOperation batchOperation = new TableBatchOperation(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(customer1); batchOperation.Insert(customer1); batchOperation.Insert(customer2); // Execute the insert operation. try { IList<TableResult> z = await table.ExecuteBatchAsync(batchOperation); foreach (var i in z) { CustomerEntity y = (CustomerEntity)i.Result; Console.WriteLine(y.PartitionKey); } var x = z; } catch (StorageException e) { var z = e.RequestInformation.HttpStatusCode; var zz = 3; }*/ }
public EventStore(CloudStorageAccount account, string tableName) { if (account == null) throw new ArgumentNullException("account"); if (tableName == null) throw new ArgumentNullException("tableName"); if (string.IsNullOrWhiteSpace(tableName)) throw new ArgumentException("tableName"); this.account = account; this.tableName = tableName; this.tableClient = account.CreateCloudTableClient(); this.tableClient.RetryPolicy = RetryPolicies.NoRetry(); // TODO: This could be injected. var backgroundRetryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)); var blockingRetryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); this.pendingEventsQueueRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(backgroundRetryStrategy); this.pendingEventsQueueRetryPolicy.Retrying += (s, e) => { var handler = this.Retrying; if (handler != null) { handler(this, EventArgs.Empty); } Trace.TraceWarning("An error occurred in attempt number {1} to access table storage (PendingEventsQueue): {0}", e.LastException.Message, e.CurrentRetryCount); }; this.eventStoreRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(blockingRetryStrategy); this.eventStoreRetryPolicy.Retrying += (s, e) => Trace.TraceWarning( "An error occurred in attempt number {1} to access table storage (EventStore): {0}", e.LastException.Message, e.CurrentRetryCount); this.eventStoreRetryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName)); }
private static RetryPolicy Exponential(ITransientErrorDetectionStrategy strategy, int retryCount, double maxBackoffDelayInSeconds, double delta) { var maxBackoff = TimeSpan.FromSeconds(maxBackoffDelayInSeconds); var deltaBackoff = TimeSpan.FromSeconds(delta); var minBackoff = TimeSpan.FromSeconds(0); var exponentialBackoff = new ExponentialBackoff(retryCount, minBackoff, maxBackoff, deltaBackoff); return new RetryPolicy(strategy, exponentialBackoff); }
public AzureMessageLogWriter(CloudStorageAccount account, string tableName) { if (account == null) throw new ArgumentNullException("account"); if (tableName == null) throw new ArgumentNullException("tableName"); if (string.IsNullOrWhiteSpace(tableName)) throw new ArgumentException("tableName"); this.account = account; this.tableName = tableName; this.tableClient = account.CreateCloudTableClient(); this.tableClient.RetryPolicy = RetryPolicies.NoRetry(); var retryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)); this.retryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy); this.retryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName)); }
public EventStore(CloudStorageAccount account, string tableName) { if (account == null) throw new ArgumentNullException("account"); if (tableName == null) throw new ArgumentNullException("tableName"); if (string.IsNullOrWhiteSpace(tableName)) throw new ArgumentException("tableName"); this.account = account; this.tableName = tableName; this.tableClient = account.CreateCloudTableClient(); this.tableClient.RetryPolicy = RetryPolicies.NoRetry(); // TODO: This could be injected. var backgroundRetryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)); var blockingRetryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); this.pendingEventsQueueRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(backgroundRetryStrategy); this.eventStoreRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(blockingRetryStrategy); this.eventStoreRetryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName)); }
public static RetryPolicy<StorageTransientErrorDetectionStrategy> GetRetryPolicy() { ExponentialBackoff retryStrategy = new ExponentialBackoff(RetryTimes, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(2)); RetryPolicy<StorageTransientErrorDetectionStrategy> retryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy); 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.TraceInformation(msg); }; return retryPolicy; }
/// <summary> /// Build a retry policy for querying Bing Maps. /// </summary> /// <returns>An initialized retry policy.</returns> private RetryPolicy BuildRetryPolicy() { RetryStrategy strategy = new ExponentialBackoff( retryCount: this.Configuration.RetryCount, minBackoff: this.Configuration.RetryMinBackOff, maxBackoff: this.Configuration.RetryMaxBackOff, deltaBackoff: this.Configuration.RetryDeltaBackOff) { FastFirstRetry = true, }; RetryPolicy policy = new RetryPolicy(new HttpErrorDetectionStrategy(), strategy); policy.Retrying += (sender, args) => this.Logger.WarnFormat("Retrying Bing Maps request due to exception: {0}", args.LastException); return policy; }