Retry

Retrying until it Succeeds

The Retry middleware reissues requests a given number of times to a backend server if that server does not reply. As soon as the server answers, the middleware stops retrying, regardless of the response status. The Retry middleware has an optional configuration to enable an exponential backoff.

Configuration Examples

Docker

  1. # Retry 4 times with exponential backoff
  2. labels:
  3. - "traefik.http.middlewares.test-retry.retry.attempts=4"
  4. - "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"

Kubernetes

  1. # Retry 4 times with exponential backoff
  2. apiVersion: traefik.io/v1alpha1
  3. kind: Middleware
  4. metadata:
  5. name: test-retry
  6. spec:
  7. retry:
  8. attempts: 4
  9. initialInterval: 100ms

Consul Catalog

  1. # Retry 4 times with exponential backoff
  2. - "traefik.http.middlewares.test-retry.retry.attempts=4"
  3. - "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"

Marathon

  1. "labels": {
  2. "traefik.http.middlewares.test-retry.retry.attempts": "4",
  3. "traefik.http.middlewares.test-retry.retry.initialinterval": "100ms",
  4. }

Rancher

  1. # Retry 4 times with exponential backoff
  2. labels:
  3. - "traefik.http.middlewares.test-retry.retry.attempts=4"
  4. - "traefik.http.middlewares.test-retry.retry.initialinterval=100ms"

File (YAML)

  1. # Retry 4 times with exponential backoff
  2. http:
  3. middlewares:
  4. test-retry:
  5. retry:
  6. attempts: 4
  7. initialInterval: 100ms

File (TOML)

  1. # Retry 4 times with exponential backoff
  2. [http.middlewares]
  3. [http.middlewares.test-retry.retry]
  4. attempts = 4
  5. initialInterval = "100ms"

Configuration Options

attempts

mandatory

The attempts option defines how many times the request should be retried.

initialInterval

The initialInterval option defines the first wait time in the exponential backoff series. The maximum interval is calculated as twice the initialInterval. If unspecified, requests will be retried immediately.

The value of initialInterval should be provided in seconds or as a valid duration format, see time.ParseDuration.