You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SendGridClient provides functionality for handling transient errors that might occur when sending an HttpRequest. The library makes use of the [Polly](https://github.com/App-vNext/Polly"Polly") package to attempt to recover from failures.
590
+
591
+
By default, retry behaviour is off, you must explicitly enable it by setting the retry count to a value greater than zero. To set the retry count, you must use the SendGridClient construct that takes a **SendGridClientOptions** object, allowing you to configure the **ReliabilitySettings**
592
+
593
+
### RetryCount
594
+
595
+
The amount of times to retry the operation before reporting an exception to the caller. This is in addition to the initial attempt, so setting a value of 1 would result in 2 attempts - the initial attempt and the retry. Defaults to zero, so retry behaviour is not enabled. The maximum amount of retries permitted is 5.
596
+
597
+
### RetryInterval
598
+
599
+
The policy implemented is a 'wait and retry'. The RetryInterval setting defines the amount of time to wait between operations that fail before attmepting a retry. By default, this is set to 1 second - the maximum amount of time allowed is 30 seconds.
600
+
601
+
## Examples
602
+
603
+
In this example, we are setting RetryCount to 1, with an interval between attempts of 5 seconds. This means that if the inital attempt to send mail fails, then it will wait 5 seconds then try again a single time.
Use the SendGridClientOptions object to set ReliabilitySettings when you want to introduce an element of resiliancy against transient faults into your solution.
/// Defines the reliability settings to use on HTTP requests
7
+
/// </summary>
8
+
publicclassReliabilitySettings
9
+
{
10
+
privateintretryCount;
11
+
12
+
privateTimeSpanretryInterval;
13
+
14
+
/// <summary>
15
+
/// Initializes a new instance of the <see cref="ReliabilitySettings"/> class.
16
+
/// </summary>
17
+
publicReliabilitySettings()
18
+
{
19
+
this.retryCount=0;
20
+
this.retryInterval=TimeSpan.FromSeconds(1);
21
+
}
22
+
23
+
/// <summary>
24
+
/// Gets or sets the number of retries to execute against an HTTP service endpoint before throwing an exceptions. Defaults to 0 (no retries, you must explicitly enable)
25
+
/// </summary>
26
+
publicintRetryCount
27
+
{
28
+
get
29
+
{
30
+
returnthis.retryCount;
31
+
}
32
+
33
+
set
34
+
{
35
+
if(value<0)
36
+
{
37
+
thrownewArgumentException("Retry count must be greater than zero");
38
+
}
39
+
40
+
if(value>5)
41
+
{
42
+
thrownewArgumentException("The maximum number of retries is 5");
43
+
}
44
+
45
+
this.retryCount=value;
46
+
}
47
+
}
48
+
49
+
/// <summary>
50
+
/// Gets or sets the interval between HTTP retries. Defaults to 1 second
51
+
/// </summary>
52
+
publicTimeSpanRetryInterval
53
+
{
54
+
get
55
+
{
56
+
returnthis.retryInterval;
57
+
}
58
+
59
+
set
60
+
{
61
+
if(value.TotalSeconds>30)
62
+
{
63
+
thrownewArgumentException("The maximum retry interval is 30 seconds");
0 commit comments