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
A circuit breaker is used to improve system stability and resiliency. It is different from the retry mechanism.
5
+
6
+
{{% hint info %}}
7
+
**Hint:** Combining the Circuit Breaker with [Retry Mechanism]({{% relref "retry-mechanism" %}}) typically provides a comprehensive approach to handling failures.
8
+
{{% /hint %}}
9
+
10
+
## Default Values
11
+
12
+
* Timeout is `10s`
13
+
* Failure threshold is `3`
14
+
* Success threshold is `1`
15
+
* Circuir break policy
16
+
* Status Code `500` and above
17
+
18
+
19
+
## Example
20
+
21
+
```go
22
+
// create circuit breaker with required values, override as required
Resty provides a way to generate the CURL command in debug mode.
4
+
Resty provides an option to generate the curl command for the request.
5
+
6
+
By default, Resty does not log the curl command in the debug log since it has the potential to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetDebugLogCurlCmd).
9
7
10
8
{{% hint info %}}
11
9
**NOTE:** Client-level settings can be overridden at the request level.
12
10
{{% /hint %}}
13
11
14
12
{{% hint warning %}}
15
13
**NOTE:**
16
-
17
-
-Potential to leak sensitive data from [Request]() and [Response]() in the debug log.
18
-
-Beware of memory usage since the request body is reread.
14
+
- Potential to leak sensitive data from [Request]({{% param Resty.V3.GoDocLinkPrefix %}}Request) and [Response]({{% param Resty.V3.GoDocLinkPrefix %}}Response) in the debug log when the debug log option is enabled.
15
+
-Additional memory usage since the request body was reread.
16
+
-curl body is not generated for `io.Reader` and multipart request flow.
The retry mechanism plays a crucial role in modern system integration by enabling effective handling of failures.
5
+
6
+
Resty provides exponential backoff with a jitter strategy out of the box; a custom retry strategy could be employed to override this default.
7
+
8
+
{{% hint info %}}
9
+
**Hint:** Combining the Retry strategy with [Circuit Breaker]({{% relref "circuit-breaker" %}}) typically provides a comprehensive approach to handling failures.
10
+
{{% /hint %}}
11
+
12
+
13
+
## Default Values
14
+
15
+
* Retry count is `0`
16
+
* Total retry attempts = `first attempt + retry count`
17
+
* Retry minimum wait time is `100ms`
18
+
* Retry maximum wait time is `2000ms`
19
+
* Retry strategy is exponential backoff with a jitter
20
+
21
+
22
+
## Default Behavior
23
+
24
+
* Respects header `Retry-After` if present
25
+
* Resets reader on retry request if the `io.ReadSeeker` interface is supported.
26
+
* Retries only on Idempotent HTTP Verb - GET, HEAD, PUT, DELETE, OPTIONS, and TRACE ([RFC 9110](https://datatracker.ietf.org/doc/html/rfc9110.html#name-method-registration), [RFC 5789](https://datatracker.ietf.org/doc/html/rfc5789.html))
27
+
* Use [Client.SetAllowNonIdempotentRetry]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetAllowNonIdempotentRetry) or [Request.SetAllowNonIdempotentRetry]({{% param Resty.V3.GoDocLinkPrefix %}}Request.SetAllowNonIdempotentRetry). If additional control is necessary, utilize the custom retry condition.
* It can be disabled via [Client.SetRetryDefaultConditions]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetRetryDefaultConditions) or [Request.SetRetryDefaultConditions]({{% param Resty.V3.GoDocLinkPrefix %}}Request.SetRetryDefaultConditions)
30
+
31
+
32
+
## Default Conditions
33
+
34
+
* Condition gets applied in the following order
35
+
* No Retry
36
+
* TLS certificate verification error
37
+
* Too many redirects error
38
+
* Scheme error
39
+
* Invalid header error
40
+
* Response is nil
41
+
* Retry
42
+
* Status Code is 429 Too Many Requests
43
+
* Status Code is 500 or above (but not Status Code 501 Not Implemented)
44
+
* Status Code is 0
45
+
46
+
47
+
## Examples
48
+
49
+
```go
50
+
// Retry configuration can be set at the client or request level
51
+
client.
52
+
SetRetryCount(3).
53
+
SetRetryWaitTime(2 * time.Second).
54
+
SetRetryMaxWaitTime(5 * time.Second)
55
+
```
56
+
57
+
### Constant Delay
58
+
59
+
Use a custom retry strategy approach to perform constant/fixed delay.
60
+
61
+
```go
62
+
// Retry configuration can be set at the client or request level
Copy file name to clipboardExpand all lines: content/docs/upgrading-to-v3.md
+42-4Lines changed: 42 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,14 @@ I made necessary breaking changes to improve Resty and open up future growth pos
27
27
28
28
* Set Content length is not applicable for `io.Reader` flow.
29
29
* By default, payload is not supported in HTTP verb DELETE. Use [Client.AllowMethodDeletePayload]({{% param Resty.V3.GoDocLinkPrefix %}}Client.AllowMethodDeletePayload) or [Request.AllowMethodDeletePayload]({{% param Resty.V3.GoDocLinkPrefix %}}Request.AllowMethodDeletePayload).
30
+
* Retry Mechanism
31
+
* Respects header `Retry-After` if present
32
+
* Resets reader on retry request if the `io.ReadSeeker` interface is supported.
33
+
* Retries only on Idempotent HTTP Verb - GET, HEAD, PUT, DELETE, OPTIONS, and TRACE ([RFC 9110](https://datatracker.ietf.org/doc/html/rfc9110.html#name-method-registration), [RFC 5789](https://datatracker.ietf.org/doc/html/rfc5789.html)),
34
+
* Use [Client.SetAllowNonIdempotentRetry]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetAllowNonIdempotentRetry) or [Request.SetAllowNonIdempotentRetry]({{% param Resty.V3.GoDocLinkPrefix %}}Request.SetAllowNonIdempotentRetry). If additional control is necessary, utilize the custom retry condition.
* It can be disabled via [Client.SetRetryDefaultConditions]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetRetryDefaultConditions) or [Request.SetRetryDefaultConditions]({{% param Resty.V3.GoDocLinkPrefix %}}Request.SetRetryDefaultConditions)
37
+
*
30
38
31
39
#### Client
32
40
@@ -40,6 +48,8 @@ I made necessary breaking changes to improve Resty and open up future growth pos
40
48
*[Client.ResponseBodyLimit]({{% param Resty.V3.GoDocLinkPrefix %}}Client.ResponseBodyLimit) - datatype changed from `int` to `int64`
*`Client.SetHostURL` - use [Client.SetBaseURL]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetBaseURL) instead.
57
72
*`Client.{SetJSONMarshaler, SetJSONUnmarshaler, SetXMLMarshaler, SetXMLUnmarshaler}` - use [Client.AddContentTypeEncoder]({{% param Resty.V3.GoDocLinkPrefix %}}Client.AddContentTypeEncoder) and [Client.AddContentTypeDecoder]({{% param Resty.V3.GoDocLinkPrefix %}}Client.AddContentTypeDecoder) instead.
58
-
*`Client.RawPathParams` - use `Client.PathParams()` instead
73
+
*`Client.RawPathParams` - use `Client.PathParams()` instead.
59
74
*`Client.UserInfo`
75
+
*`Client.SetRetryResetReaders` - it happens automatically.
76
+
*`Client.SetRetryAfter` - use [Client.SetRetryStrategy]({{% param Resty.V3.GoDocLinkPrefix %}}Client.SetRetryStrategy) or [Request.SetRetryStrategy]({{% param Resty.V3.GoDocLinkPrefix %}}Request.SetRetryStrategy) instead.
60
77
61
78
#### Request
62
79
63
80
*`Request.RawPathParams` - use [Request.PathParams]({{% param Resty.V3.GoDocLinkPrefix %}}Request.PathParams) instead
81
+
*
64
82
65
83
#### Response
66
84
@@ -79,6 +97,10 @@ I made necessary breaking changes to improve Resty and open up future growth pos
79
97
80
98
## New Features and Enhancements
81
99
100
+
* Override all transport settings and timeout values used by Resty using [NewWithTransportSettings]({{% param Resty.V3.GoDocLinkPrefix %}}NewWithTransportSettings)
0 commit comments