2019-04-08 15:14:08 +00:00
# Retry
2019-02-26 13:50:07 +00:00
Retrying until it Succeeds
{: .subtitle }
2019-09-10 12:40:05 +00:00
<!--
TODO: add schema
-->
2019-02-26 13:50:07 +00:00
2019-09-04 15:28:03 +00:00
The Retry middleware is in charge of reissuing a request a given number of times to a backend server if that server does not reply.
To be clear, as soon as the server answers, the middleware stops retrying, regardless of the response status.
2020-11-05 15:14:04 +00:00
The Retry middleware has an optional configuration for exponential backoff.
2019-02-26 13:50:07 +00:00
2019-04-08 15:14:08 +00:00
## Configuration Examples
2019-02-26 13:50:07 +00:00
2019-04-08 15:14:08 +00:00
```yaml tab="Docker"
2020-11-05 15:14:04 +00:00
# Retry to send request 4 times with exponential backoff
2019-04-08 15:14:08 +00:00
labels:
2019-09-23 15:00:06 +00:00
- "traefik.http.middlewares.test-retry.retry.attempts=4"
2020-11-05 15:14:04 +00:00
- "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"
2019-02-26 13:50:07 +00:00
```
2019-04-08 15:14:08 +00:00
```yaml tab="Kubernetes"
2020-11-05 15:14:04 +00:00
# Retry to send request 4 times with exponential backoff
2019-04-08 15:14:08 +00:00
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: test-retry
spec:
retry:
attempts: 4
2020-11-05 15:14:04 +00:00
initialInterval: 100ms
2019-04-08 15:14:08 +00:00
```
2019-10-15 15:34:08 +00:00
```yaml tab="Consul Catalog"
2020-11-05 15:14:04 +00:00
# Retry to send request 4 times with exponential backoff
2019-10-15 15:34:08 +00:00
- "traefik.http.middlewares.test-retry.retry.attempts=4"
2020-11-05 15:14:04 +00:00
- "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"
2019-10-15 15:34:08 +00:00
```
2019-04-15 16:22:07 +00:00
```json tab="Marathon"
"labels": {
2020-11-05 15:14:04 +00:00
"traefik.http.middlewares.test-retry.retry.attempts": "4",
"traefik.http.middlewares.test-retry.retry.initialinterval": "100ms",
2019-04-15 16:22:07 +00:00
}
```
2019-04-08 15:14:08 +00:00
```yaml tab="Rancher"
2020-11-05 15:14:04 +00:00
# Retry to send request 4 times with exponential backoff
2019-04-08 15:14:08 +00:00
labels:
2019-09-23 15:00:06 +00:00
- "traefik.http.middlewares.test-retry.retry.attempts=4"
2020-11-05 15:14:04 +00:00
- "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"
2019-04-08 15:14:08 +00:00
```
2019-07-22 07:58:04 +00:00
```toml tab="File (TOML)"
2019-04-08 15:14:08 +00:00
# Retry to send request 4 times
[http.middlewares]
2019-07-01 09:30:05 +00:00
[http.middlewares.test-retry.retry]
2020-11-05 15:14:04 +00:00
attempts = 4
initialInterval = "100ms"
2019-04-08 15:14:08 +00:00
```
2019-07-22 07:58:04 +00:00
```yaml tab="File (YAML)"
2020-11-05 15:14:04 +00:00
# Retry to send request 4 times with exponential backoff
2019-07-22 07:58:04 +00:00
http:
middlewares:
test-retry:
retry:
2020-11-05 15:14:04 +00:00
attempts: 4
initialInterval: 100ms
2019-07-22 07:58:04 +00:00
```
2019-04-08 15:14:08 +00:00
## Configuration Options
2020-11-05 15:14:04 +00:00
### `attempts`
2019-04-08 15:14:08 +00:00
_mandatory_
2019-09-23 15:00:06 +00:00
The `attempts` option defines how many times the request should be retried.
2020-11-05 15:14:04 +00:00
### `initialInterval`
The `initialInterval` option defines the first wait time in the exponential backoff series (provided in seconds or as a valid duration format, see [time.ParseDuration ](https://golang.org/pkg/time/#ParseDuration )). The maximum interval is calculated as twice the `initialInterval` . If unspecified, requests will be retried immediately.