Skip to content

[EventHubs] Provide an linear(fixed) backoff option for retry #8670

@annatisch

Description

@annatisch

Feature Wanted:

We need to add support for Fixed(Linear) retry backoff in EventHubs. EventHub needs to implement its own retry as it's based on amqp protocol so we can't simply reuse the azure-core which is http-based. However, the design of retry is almost the same.

Currently EH only supports exponential back off mode, and it takes three retry related key-word arguments when constructing the EventHubProducerClient/EventHubConsumerClient -- retry_backoff_factor, retry_backoff_max, retry_total.

As per azure-core:

class RetryPolicy(HTTPPolicy):
"""A retry policy.
The retry policy in the pipeline can be configured directly, or tweaked on a per-call basis.
:keyword int retry_total: Total number of retries to allow. Takes precedence over other counts.
Default value is 10.
:keyword int retry_connect: How many connection-related errors to retry on.
These are errors raised before the request is sent to the remote server,
which we assume has not triggered the server to process the request. Default value is 3.
:keyword int retry_read: How many times to retry on read errors.
These errors are raised after the request was sent to the server, so the
request may have side-effects. Default value is 3.
:keyword int retry_status: How many times to retry on bad status codes. Default value is 3.
:keyword float retry_backoff_factor: A backoff factor to apply between attempts after the second try
(most errors are resolved immediately by a second try without a delay).
In fixed mode, retry policy will alwasy sleep for {backoff factor}.
In 'exponential' mode, retry policy will sleep for: `{backoff factor} * (2 ** ({number of total retries} - 1))`
seconds. If the backoff_factor is 0.1, then the retry will sleep
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
:keyword int retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
:keyword RetryMode retry_mode: Fixed or exponential delay between attemps, default is exponential.
:keyword int timeout: Timeout setting for the operation in seconds, default is 604800s (7 days).

Action items:

  1. Need to define the enum type RetryMode under azure.eventhub namespace -- azure.eventhub.RetryMode
    https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/azure/core/pipeline/policies/_retry.py#L52-L54
class RetryMode(str, Enum):
    Exponential = 'exponential'
    Fixed = 'fixed'
  1. EventHubProducerClient/EventHubConsumerClient (and async) constructors and the helper method from_connection_string should take "retry_mode" as a key-word argument and the default value shall be Exponential (non-breaking change), see configuration and how the configuration could be used internally.

  2. Update the def _backoff and the async version to backoff according to the given retry mode.

  3. Test and docstring

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Event HubsMQThis issue is part of a "milestone of quality" initiative.MessagingMessaging crewP0help wantedThis issue is tracking work for which community contributions would be welcomed and appreciated

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions