Skip to content

Commit e358eb4

Browse files
authored
[ServiceBus&EventHubs] remove RetryMode enum (#22369)
* remove RetryMode from SB * remove RetryMode from EH * annas comments
1 parent 9a544e9 commit e358eb4

19 files changed

+97
-67
lines changed

sdk/eventhub/azure-eventhub/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ This version and all future versions will require Python 3.7+. Python 2.7 and 3.
88

99
- Added support for fixed (linear) retry backoff:
1010
- Sync/async `EventHubProducerClient` and `EventHubConsumerClient` constructors and `from_connection_string` take `retry_mode` as a keyword argument.
11-
- `RetryMode` enum has been added to `azure.eventhub`, with values `FIXED` and `EXPONENTIAL`.
1211

1312
### Breaking Changes
1413

sdk/eventhub/azure-eventhub/azure/eventhub/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
parse_connection_string,
1919
EventHubConnectionStringProperties
2020
)
21-
from ._retry import RetryMode
2221

2322
TransportType = constants.TransportType
2423

@@ -35,5 +34,4 @@
3534
"PartitionContext",
3635
"parse_connection_string",
3736
"EventHubConnectionStringProperties",
38-
"RetryMode"
3937
]

sdk/eventhub/azure-eventhub/azure/eventhub/_client_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
AzureNamedKeyCredential,
2727
)
2828
from azure.core.utils import parse_connection_string as core_parse_connection_string
29+
from azure.core.pipeline.policies import RetryMode
2930

3031

3132
from .exceptions import _handle_exception, ClientClosedError, ConnectError
3233
from ._configuration import Configuration
33-
from ._retry import RetryMode
3434
from ._utils import utc_from_timestamp, parse_sas_credential
3535
from ._connection_manager import get_connection_manager
3636
from ._constants import (
@@ -164,7 +164,7 @@ def _build_uri(address, entity):
164164

165165

166166
def _get_backoff_time(retry_mode, backoff_factor, backoff_max, retried_times):
167-
if retry_mode == RetryMode.FIXED:
167+
if retry_mode == RetryMode.Fixed:
168168
backoff_value = backoff_factor
169169
else:
170170
backoff_value = backoff_factor * (2 ** retried_times)

sdk/eventhub/azure-eventhub/azure/eventhub/_configuration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
from urllib.parse import urlparse
1111

1212
from uamqp.constants import TransportType, DEFAULT_AMQPS_PORT, DEFAULT_AMQP_WSS_PORT
13-
from ._retry import RetryMode
13+
from azure.core.pipeline.policies import RetryMode
1414

1515

1616
class Configuration(object): # pylint:disable=too-many-instance-attributes
1717
def __init__(self, **kwargs):
1818
self.user_agent = kwargs.get("user_agent") # type: Optional[str]
1919
self.retry_total = kwargs.get("retry_total", 3) # type: int
2020
self.max_retries = self.retry_total # type: int
21-
self.retry_mode = kwargs.get("retry_mode", RetryMode.EXPONENTIAL)
21+
self.retry_mode = RetryMode(kwargs.get("retry_mode", "exponential"))
2222
self.backoff_factor = kwargs.get("retry_backoff_factor", 0.8) # type: float
2323
self.backoff_max = kwargs.get("retry_backoff_max", 120) # type: int
2424
self.network_tracing = kwargs.get("network_tracing", False) # type: bool

sdk/eventhub/azure-eventhub/azure/eventhub/_consumer_client.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
if TYPE_CHECKING:
1717
import datetime
18-
from azure.core.credentials import TokenCredential, AzureSasCredential, AzureNamedKeyCredential
18+
from azure.core.credentials import (
19+
TokenCredential,
20+
AzureSasCredential,
21+
AzureNamedKeyCredential,
22+
)
1923
from typing import ( # pylint: disable=ungrouped-imports
2024
Any,
2125
Union,
@@ -79,8 +83,9 @@ class EventHubConsumerClient(ClientBase):
7983
seconds. If the backoff_factor is 0.1, then the retry will sleep
8084
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
8185
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
82-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
83-
:paramtype retry_mode: ~azure.eventhub.RetryMode
86+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
87+
where default is 'exponential'.
88+
:paramtype retry_mode: str
8489
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
8590
if there is no further activity. By default the value is None, meaning that the client will not shutdown due to
8691
inactivity unless initiated by the service.
@@ -151,10 +156,15 @@ def __init__(
151156
"partition_ownership_expiration_interval", None
152157
)
153158
if self._partition_ownership_expiration_interval is None:
154-
self._partition_ownership_expiration_interval = 6 * self._load_balancing_interval
159+
self._partition_ownership_expiration_interval = (
160+
6 * self._load_balancing_interval
161+
)
155162
load_balancing_strategy = kwargs.pop("load_balancing_strategy", None)
156-
self._load_balancing_strategy = LoadBalancingStrategy(load_balancing_strategy) if load_balancing_strategy \
163+
self._load_balancing_strategy = (
164+
LoadBalancingStrategy(load_balancing_strategy)
165+
if load_balancing_strategy
157166
else LoadBalancingStrategy.GREEDY
167+
)
158168
self._consumer_group = consumer_group
159169
network_tracing = kwargs.pop("logging_enable", False)
160170
super(EventHubConsumerClient, self).__init__(
@@ -235,8 +245,9 @@ def from_connection_string(cls, conn_str, consumer_group, **kwargs):
235245
seconds. If the backoff_factor is 0.1, then the retry will sleep
236246
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
237247
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
238-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
239-
:paramtype retry_mode: ~azure.eventhub.RetryMode
248+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
249+
where default is 'exponential'.
250+
:paramtype retry_mode: str
240251
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
241252
if there is no furthur activity. By default the value is None, meaning that the client will not shutdown due
242253
to inactivity unless initiated by the service.

sdk/eventhub/azure-eventhub/azure/eventhub/_producer_client.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ class EventHubProducerClient(ClientBase):
5454
seconds. If the backoff_factor is 0.1, then the retry will sleep
5555
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
5656
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
57-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
58-
:paramtype retry_mode: ~azure.eventhub.RetryMode
57+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
58+
where default is 'exponential'.
59+
:paramtype retry_mode: str
5960
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
6061
if there is no activity. By default the value is None, meaning that the client will not shutdown due to inactivity
6162
unless initiated by the service.
@@ -201,8 +202,9 @@ def from_connection_string(cls, conn_str, **kwargs):
201202
seconds. If the backoff_factor is 0.1, then the retry will sleep
202203
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
203204
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
204-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
205-
:paramtype retry_mode: ~azure.eventhub.RetryMode
205+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
206+
where default is 'exponential'.
207+
:paramtype retry_mode: str
206208
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
207209
if there is no activity. By default the value is None, meaning that the client will not shutdown due to
208210
inactivity unless initiated by the service.

sdk/eventhub/azure-eventhub/azure/eventhub/_retry.py

-9
This file was deleted.

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_consumer_client_async.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ class EventHubConsumerClient(ClientBaseAsync):
8686
seconds. If the backoff_factor is 0.1, then the retry will sleep
8787
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
8888
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
89-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
90-
:paramtype retry_mode: ~azure.eventhub.RetryMode
89+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
90+
where default is 'exponential'.
91+
:paramtype retry_mode: str
9192
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
9293
if there is no further activity. By default the value is None, meaning that the client will not shutdown due to
9394
inactivity unless initiated by the service.
@@ -255,8 +256,9 @@ def from_connection_string(
255256
seconds. If the backoff_factor is 0.1, then the retry will sleep
256257
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
257258
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
258-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
259-
:paramtype retry_mode: ~azure.eventhub.RetryMode
259+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
260+
where default is 'exponential'.
261+
:paramtype retry_mode: str
260262
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
261263
if there is no further activity. By default the value is None, meaning that the client will not shutdown due
262264
to inactivity unless initiated by the service.

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_producer_client_async.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ class EventHubProducerClient(ClientBaseAsync):
5353
seconds. If the backoff_factor is 0.1, then the retry will sleep
5454
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
5555
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
56-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
57-
:paramtype retry_mode: ~azure.eventhub.RetryMode
56+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
57+
where default is 'exponential'.
58+
:paramtype retry_mode: str
5859
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
5960
if there is no activity. By default the value is None, meaning that the client will not shutdown due to inactivity
6061
unless initiated by the service.
@@ -217,8 +218,9 @@ def from_connection_string(
217218
seconds. If the backoff_factor is 0.1, then the retry will sleep
218219
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.
219220
:keyword float retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
220-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
221-
:paramtype retry_mode: ~azure.eventhub.RetryMode
221+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
222+
where default is 'exponential'.
223+
:paramtype retry_mode: str
222224
:keyword float idle_timeout: Timeout, in seconds, after which this client will close the underlying connection
223225
if there is no activity. By default the value is None, meaning that the client will not shutdown due to
224226
inactivity unless initiated by the service.

sdk/eventhub/azure-eventhub/tests/unittest/test_client_creation.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#--------------------------------------------------------------------------
66

77
import time
8-
from azure.eventhub import EventHubProducerClient, EventHubConsumerClient, TransportType, RetryMode
8+
from azure.core.pipeline.policies import RetryMode
9+
from azure.eventhub import EventHubProducerClient, EventHubConsumerClient, TransportType
910

1011

1112
def test_custom_endpoint():
@@ -136,13 +137,28 @@ def test_backoff_fixed_retry():
136137
'fake.host.com',
137138
'fake_eh',
138139
None,
139-
retry_mode=RetryMode.FIXED
140+
retry_mode='fixed'
140141
)
141142
backoff = client._config.backoff_factor
142143
start_time = time.time()
143144
client._backoff(retried_times=1, last_exception=Exception('fake'), timeout_time=None)
144145
sleep_time = time.time() - start_time
145146
# exp = 0.8 * (2 ** 1) = 1.6
146-
# time.sleep() in _backoff will take AT LEAST time 'exp' for RetryMode.EXPONENTIAL
147+
# time.sleep() in _backoff will take AT LEAST time 'exp' for 'exponential'
148+
# check that fixed is less than 'exp'
149+
assert sleep_time < backoff * (2 ** 1)
150+
151+
client = EventHubProducerClient(
152+
'fake.host.com',
153+
'fake_eh',
154+
None,
155+
retry_mode=RetryMode.Fixed
156+
)
157+
backoff = client._config.backoff_factor
158+
start_time = time.time()
159+
client._backoff(retried_times=1, last_exception=Exception('fake'), timeout_time=None)
160+
sleep_time = time.time() - start_time
161+
# exp = 0.8 * (2 ** 1) = 1.6
162+
# time.sleep() in _backoff will take AT LEAST time 'exp' for 'exponential'
147163
# check that fixed is less than 'exp'
148164
assert sleep_time < backoff * (2 ** 1)

sdk/servicebus/azure-servicebus/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ This version and all future versions will require Python 3.7+. Python 2.7 and 3.
88

99
- Added support for fixed (linear) retry backoff:
1010
- Sync/async `ServiceBusClient` constructors and `from_connection_string` take `retry_mode` as a keyword argument.
11-
- `RetryMode` enum has been added to `azure.servicebus`, with values `FIXED` and `EXPONENTIAL`.
1211

1312
### Breaking Changes
1413

sdk/servicebus/azure-servicebus/azure/servicebus/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
parse_connection_string,
2929
ServiceBusConnectionStringProperties,
3030
)
31-
from ._retry import RetryMode
3231

3332
TransportType = constants.TransportType
3433

@@ -47,5 +46,4 @@
4746
"AutoLockRenewer",
4847
"parse_connection_string",
4948
"ServiceBusConnectionStringProperties",
50-
"RetryMode",
5149
]

sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from uamqp.message import MessageProperties
2121

2222
from azure.core.credentials import AccessToken, AzureSasCredential, AzureNamedKeyCredential
23+
from azure.core.pipeline.policies import RetryMode
2324

2425
from ._common._configuration import Configuration
25-
from ._retry import RetryMode
2626
from .exceptions import (
2727
ServiceBusError,
2828
ServiceBusConnectionError,
@@ -154,7 +154,7 @@ def _generate_sas_token(uri, policy, key, expiry=None):
154154
return AccessToken(token=token, expires_on=abs_expiry)
155155

156156
def _get_backoff_time(retry_mode, backoff_factor, backoff_max, retried_times):
157-
if retry_mode == RetryMode.FIXED:
157+
if retry_mode == RetryMode.Fixed:
158158
backoff_value = backoff_factor
159159
else:
160160
backoff_value = backoff_factor * (2 ** retried_times)

sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from typing import Optional, Dict, Any
66

77
from uamqp.constants import TransportType
8-
from .._retry import RetryMode
8+
from azure.core.pipeline.policies import RetryMode
99

1010

1111
class Configuration(object): # pylint:disable=too-many-instance-attributes
1212
def __init__(self, **kwargs):
1313
self.user_agent = kwargs.get("user_agent") # type: Optional[str]
1414
self.retry_total = kwargs.get("retry_total", 3) # type: int
15-
self.retry_mode = kwargs.get("retry_mode", RetryMode.EXPONENTIAL)
15+
self.retry_mode = RetryMode(kwargs.get("retry_mode", 'exponential'))
1616
self.retry_backoff_factor = kwargs.get(
1717
"retry_backoff_factor", 0.8
1818
) # type: float

sdk/servicebus/azure-servicebus/azure/servicebus/_retry.py

-9
This file was deleted.

sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ class ServiceBusClient(object):
6060
:keyword float retry_backoff_factor: Delta back-off internal in the unit of second between retries.
6161
Default value is 0.8.
6262
:keyword float retry_backoff_max: Maximum back-off interval in the unit of second. Default value is 120.
63-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
64-
:paramtype retry_mode: ~azure.servicebus.RetryMode
63+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
64+
where default is 'exponential'.
65+
:paramtype retry_mode: str
6566
6667
.. admonition:: Example:
6768
@@ -154,8 +155,9 @@ def from_connection_string(cls, conn_str, **kwargs):
154155
:keyword float retry_backoff_factor: Delta back-off internal in the unit of second between retries.
155156
Default value is 0.8.
156157
:keyword float retry_backoff_max: Maximum back-off interval in the unit of second. Default value is 120.
157-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
158-
:paramtype retry_mode: ~azure.servicebus.RetryMode
158+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
159+
where default is 'exponential'.
160+
:paramtype retry_mode: str
159161
:rtype: ~azure.servicebus.ServiceBusClient
160162
161163
.. admonition:: Example:

sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ class ServiceBusClient(object):
5858
:keyword float retry_backoff_factor: Delta back-off internal in the unit of second between retries.
5959
Default value is 0.8.
6060
:keyword float retry_backoff_max: Maximum back-off interval in the unit of second. Default value is 120.
61-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
62-
:paramtype retry_mode: ~azure.eventhub.RetryMode
61+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
62+
where default is 'exponential'.
63+
:paramtype retry_mode: str
6364
6465
.. admonition:: Example:
6566
@@ -131,8 +132,9 @@ def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "ServiceBusClie
131132
:keyword float retry_backoff_factor: Delta back-off internal in the unit of second between retries.
132133
Default value is 0.8.
133134
:keyword float retry_backoff_max: Maximum back-off interval in the unit of second. Default value is 120.
134-
:keyword retry_mode: Fixed or exponential delay between attempts, default is exponential.
135-
:paramtype retry_mode: ~azure.eventhub.RetryMode
135+
:keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential',
136+
where default is 'exponential'.
137+
:paramtype retry_mode: str
136138
:rtype: ~azure.servicebus.aio.ServiceBusClient
137139
138140
.. admonition:: Example:

sdk/servicebus/azure-servicebus/tests/async_tests/test_sb_client_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ async def test_backoff_fixed_retry(self):
407407
client = ServiceBusClient(
408408
'fake.host.com',
409409
'fake_eh',
410-
retry_mode=RetryMode.FIXED
410+
retry_mode='fixed'
411411
)
412412
# queue sender
413413
sender = await client.get_queue_sender('fake_name')
@@ -416,7 +416,7 @@ async def test_backoff_fixed_retry(self):
416416
sender._backoff(retried_times=1, last_exception=Exception('fake'), abs_timeout_time=None)
417417
sleep_time_fixed = time.time() - start_time
418418
# exp = 0.8 * (2 ** 1) = 1.6
419-
# time.sleep() in _backoff will take AT LEAST time 'exp' for RetryMode.EXPONENTIAL
419+
# time.sleep() in _backoff will take AT LEAST time 'exp' for retry_mode='exponential'
420420
# check that fixed is less than 'exp'
421421
assert sleep_time_fixed < backoff * (2 ** 1)
422422

0 commit comments

Comments
 (0)