public S3Client(S3Config config, HttpMessageHandler messageHandler) { ServiceCollection services = new ServiceCollection(); services.AddSingleton(x => Options.Create(config)); IS3ClientBuilder builder = services.AddSimpleS3Core(); IHttpClientBuilder httpBuilder = builder.UseHttpClientFactory(); if (messageHandler != null) { httpBuilder.ConfigurePrimaryHttpMessageHandler(x => messageHandler); } httpBuilder.SetHandlerLifetime(TimeSpan.FromMinutes(5)); Random random = new Random(); // Policy is: // Retries: 3 // Timeout: 2^attempt seconds (2, 4, 8 seconds) + -100 to 100 ms jitter httpBuilder.AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)) + TimeSpan.FromMilliseconds(random.Next(-100, 100)))); _provider = services.BuildServiceProvider(); _objectClient = _provider.GetRequiredService <IS3ObjectClient>(); _bucketClient = _provider.GetRequiredService <IS3BucketClient>(); _serviceClient = _provider.GetRequiredService <IS3ServiceClient>(); }
public static async IAsyncEnumerable <S3Bucket> GetServiceAllAsync(this IS3ServiceClient client, Action <GetServiceRequest> config = null, [EnumeratorCancellation] CancellationToken token = default) { Validator.RequireNotNull(client); GetServiceResponse resp = await client.GetServiceAsync(config, token).ConfigureAwait(false); foreach (S3Bucket respBucket in resp.Buckets) { yield return(respBucket); } }