| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Diagnostics.CodeAnalysis; |
| | 6 | | using Azure.Core; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.EventHubs |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The set of options that can be specified to influence how |
| | 12 | | /// retry attempts are made, and a failure is eligible to be retried. |
| | 13 | | /// </summary> |
| | 14 | | /// |
| | 15 | | public class EventHubsRetryOptions |
| | 16 | | { |
| | 17 | | /// <summary>The maximum number of retry attempts before considering the associated operation to have failed.</s |
| 1560 | 18 | | private int _maximumRetries = 3; |
| | 19 | |
|
| | 20 | | /// <summary>The delay or back-off factor to apply between retry attempts.</summary> |
| 1560 | 21 | | private TimeSpan _delay = TimeSpan.FromSeconds(0.8); |
| | 22 | |
|
| | 23 | | /// <summary>The maximum delay to allow between retry attempts.</summary> |
| 1560 | 24 | | private TimeSpan _maximumDelay = TimeSpan.FromMinutes(1); |
| | 25 | |
|
| | 26 | | /// <summary>The maximum duration to wait for an operation, per attempt.</summary> |
| 1560 | 27 | | private TimeSpan _tryTimeout = TimeSpan.FromMinutes(1); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// The approach to use for calculating retry delays. |
| | 31 | | /// </summary> |
| | 32 | | /// |
| 2818 | 33 | | public EventHubsRetryMode Mode { get; set; } = EventHubsRetryMode.Exponential; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The maximum number of retry attempts before considering the associated operation |
| | 37 | | /// to have failed. |
| | 38 | | /// </summary> |
| | 39 | | /// |
| | 40 | | public int MaximumRetries |
| | 41 | | { |
| 1946 | 42 | | get => _maximumRetries; |
| | 43 | |
|
| | 44 | | set |
| | 45 | | { |
| 394 | 46 | | Argument.AssertInRange(value, 0, 100, nameof(MaximumRetries)); |
| 382 | 47 | | _maximumRetries = value; |
| 382 | 48 | | } |
| | 49 | | } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// The delay between retry attempts for a fixed approach or the delay |
| | 53 | | /// on which to base calculations for a backoff-based approach. |
| | 54 | | /// </summary> |
| | 55 | | /// |
| | 56 | | public TimeSpan Delay |
| | 57 | | { |
| 2862 | 58 | | get => _delay; |
| | 59 | |
|
| | 60 | | set |
| | 61 | | { |
| 358 | 62 | | Argument.AssertInRange(value, TimeSpan.FromMilliseconds(1), TimeSpan.FromMinutes(5), nameof(Delay)); |
| 344 | 63 | | _delay = value; |
| 344 | 64 | | } |
| | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// The maximum permissible delay between retry attempts. |
| | 69 | | /// </summary> |
| | 70 | | /// |
| | 71 | | public TimeSpan MaximumDelay |
| | 72 | | { |
| 1740 | 73 | | get => _maximumDelay; |
| | 74 | |
|
| | 75 | | set |
| | 76 | | { |
| 380 | 77 | | Argument.AssertNotNegative(value, nameof(MaximumDelay)); |
| 374 | 78 | | _maximumDelay = value; |
| 374 | 79 | | } |
| | 80 | | } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// The maximum duration to wait for completion of a single attempt, whether the initial |
| | 84 | | /// attempt or a retry. |
| | 85 | | /// </summary> |
| | 86 | | /// |
| | 87 | | [SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "We believe using |
| | 88 | | public TimeSpan TryTimeout |
| | 89 | | { |
| 496 | 90 | | get => _tryTimeout; |
| | 91 | |
|
| | 92 | | set |
| | 93 | | { |
| 242 | 94 | | if (value < TimeSpan.Zero) |
| | 95 | | { |
| 6 | 96 | | throw new ArgumentException(Resources.TimeoutMustBePositive, nameof(TryTimeout)); |
| | 97 | | } |
| | 98 | |
|
| 236 | 99 | | Argument.AssertInRange(value, TimeSpan.Zero, TimeSpan.FromHours(1), nameof(TryTimeout)); |
| 230 | 100 | | _tryTimeout = value; |
| 230 | 101 | | } |
| | 102 | | } |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// A custom retry policy to be used in place of the individual option values. |
| | 106 | | /// </summary> |
| | 107 | | /// |
| | 108 | | /// <remarks> |
| | 109 | | /// When populated, this custom policy will take precedence over the individual retry |
| | 110 | | /// options provided. |
| | 111 | | /// </remarks> |
| | 112 | | /// |
| 1116 | 113 | | public EventHubsRetryPolicy CustomRetryPolicy { get; set; } |
| | 114 | | } |
| | 115 | | } |