From e4792ffbec212aa04607dc54dbef0500a00e26cb Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 20 Jun 2023 20:02:00 -0700 Subject: [PATCH 01/50] attempt to set timeout on link properties --- .../azure-servicebus/azure/servicebus/_common/constants.py | 1 + .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/constants.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/constants.py index 204895a17475..752af614e481 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/constants.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/constants.py @@ -61,6 +61,7 @@ CONSUMER_IDENTIFIER = VENDOR + b":receiver-name" UAMQP_LIBRARY = "uamqp" PYAMQP_LIBRARY = "pyamqp" +OPERATION_TIMEOUT = VENDOR + b":timeout" MANAGEMENT_PATH_SUFFIX = "/$management" diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index a3635c007aa3..c69838ed9169 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -47,6 +47,7 @@ MGMT_REQUEST_DEAD_LETTER_REASON, MGMT_REQUEST_DEAD_LETTER_ERROR_DESCRIPTION, MGMT_RESPONSE_MESSAGE_EXPIRATION, + OPERATION_TIMEOUT ) from ._common import mgmt_handlers from ._common.receiver_mixins import ReceiverMixin @@ -364,7 +365,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties={CONSUMER_IDENTIFIER: self._name}, + link_properties={CONSUMER_IDENTIFIER: self._name, OPERATION_TIMEOUT: self._max_wait_time}, ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. From 36e292794c5a719fe21458d02b92c75b699bb2df Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 22 Jun 2023 10:15:16 -0700 Subject: [PATCH 02/50] jitter math --- .../azure/servicebus/_servicebus_receiver.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index c69838ed9169..005dda218c85 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -5,6 +5,8 @@ # pylint:disable=too-many-lines import threading import time +import math +import random import logging import functools import uuid @@ -47,7 +49,8 @@ MGMT_REQUEST_DEAD_LETTER_REASON, MGMT_REQUEST_DEAD_LETTER_ERROR_DESCRIPTION, MGMT_RESPONSE_MESSAGE_EXPIRATION, - OPERATION_TIMEOUT + OPERATION_TIMEOUT, + NEXT_AVAILABLE_SESSION ) from ._common import mgmt_handlers from ._common.receiver_mixins import ReceiverMixin @@ -345,6 +348,16 @@ def _from_connection_string( def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth"]) -> None: + if self._session._session_id == NEXT_AVAILABLE_SESSION: + timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 + open_receive_link_base_jitter_in_ms = 100 + open_recieve_link_buffer_in_ms = 20 + open_receive_link_buffer_threshold_in_ms = 1000 + jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + timeout_in_ms -= open_recieve_link_buffer_in_ms + self._handler = self._amqp_transport.create_receive_client( receiver=self, source=self._get_source(), @@ -365,7 +378,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties={CONSUMER_IDENTIFIER: self._name, OPERATION_TIMEOUT: self._max_wait_time}, + link_properties={CONSUMER_IDENTIFIER: self._name, OPERATION_TIMEOUT: timeout_in_ms}, ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. From 6a43cb84793cad2686d4d7b2cb91a46003a74e5f Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 5 Jul 2023 10:07:46 -0700 Subject: [PATCH 03/50] update receiver logic --- .../azure/servicebus/_servicebus_receiver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 005dda218c85..428cec26494c 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -347,7 +347,7 @@ def _from_connection_string( return cls(**constructor_args) def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth"]) -> None: - + link_properties = {CONSUMER_IDENTIFIER: self._name} if self._session._session_id == NEXT_AVAILABLE_SESSION: timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 open_receive_link_base_jitter_in_ms = 100 @@ -357,6 +357,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: timeout_in_ms -= open_recieve_link_buffer_in_ms + link_properties[OPERATION_TIMEOUT] = timeout_in_ms self._handler = self._amqp_transport.create_receive_client( receiver=self, @@ -378,7 +379,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties={CONSUMER_IDENTIFIER: self._name, OPERATION_TIMEOUT: timeout_in_ms}, + link_properties=link_properties, ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. From 07cf44232a3ee38b0b4e0bbd2bc5cae2531dcfee Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 6 Jul 2023 15:01:15 -0700 Subject: [PATCH 04/50] update encode --- .../azure/servicebus/_pyamqp/_encode.py | 2 ++ .../azure/servicebus/_servicebus_receiver.py | 16 ++++++++-------- .../servicebus/aio/_servicebus_receiver_async.py | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py index b224d28efa8b..96476cdef28d 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py @@ -614,6 +614,8 @@ def encode_fields(value): return {TYPE: AMQPTypes.null, VALUE: None} fields = {TYPE: AMQPTypes.map, VALUE: []} for key, data in value.items(): + if key == b'com.microsoft:timeout': + data = {'TYPE': AMQPTypes.uint, 'VALUE': data} if isinstance(key, str): key = key.encode("utf-8") # type: ignore cast(List, fields[VALUE]).append(({TYPE: AMQPTypes.symbol, VALUE: key}, data)) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 428cec26494c..54405240fcca 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -350,14 +350,14 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth link_properties = {CONSUMER_IDENTIFIER: self._name} if self._session._session_id == NEXT_AVAILABLE_SESSION: timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 - open_receive_link_base_jitter_in_ms = 100 - open_recieve_link_buffer_in_ms = 20 - open_receive_link_buffer_threshold_in_ms = 1000 - jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) - timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) - if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: - timeout_in_ms -= open_recieve_link_buffer_in_ms - link_properties[OPERATION_TIMEOUT] = timeout_in_ms + # open_receive_link_base_jitter_in_ms = 100 + # open_recieve_link_buffer_in_ms = 20 + # open_receive_link_buffer_threshold_in_ms = 1000 + # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + # timeout_in_ms -= open_recieve_link_buffer_in_ms + link_properties[OPERATION_TIMEOUT] = timeout_in_ms - 100 self._handler = self._amqp_transport.create_receive_client( receiver=self, diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 74311b4ccf32..60ea72b446fd 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -49,6 +49,8 @@ MGMT_REQUEST_DEAD_LETTER_REASON, MGMT_REQUEST_DEAD_LETTER_ERROR_DESCRIPTION, MGMT_RESPONSE_MESSAGE_EXPIRATION, + OPERATION_TIMEOUT, + NEXT_AVAILABLE_SESSION ) from .._common import mgmt_handlers from .._common.utils import utc_from_timestamp @@ -341,6 +343,17 @@ def _from_connection_string( return cls(**constructor_args) def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTTokenAuthAsync"]) -> None: + link_properties = {CONSUMER_IDENTIFIER: self._name} + if self._session._session_id == NEXT_AVAILABLE_SESSION: + timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 + # open_receive_link_base_jitter_in_ms = 100 + # open_recieve_link_buffer_in_ms = 20 + # open_receive_link_buffer_threshold_in_ms = 1000 + # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + # timeout_in_ms -= open_recieve_link_buffer_in_ms + link_properties[OPERATION_TIMEOUT] = timeout_in_ms - 100 self._handler = self._amqp_transport.create_receive_client_async( receiver=self, @@ -362,7 +375,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTToke if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties = {CONSUMER_IDENTIFIER:self._name} + link_properties = link_properties ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. From 0c47666f12714fb06b343d3856c2c8d203c43f76 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 6 Jul 2023 15:34:37 -0700 Subject: [PATCH 05/50] move logic to pyamqp_transport --- .../azure/servicebus/_pyamqp/_encode.py | 2 -- .../azure/servicebus/_transport/_pyamqp_transport.py | 9 +++++++++ .../aio/_transport/_pyamqp_transport_async.py | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py index 96476cdef28d..b224d28efa8b 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_encode.py @@ -614,8 +614,6 @@ def encode_fields(value): return {TYPE: AMQPTypes.null, VALUE: None} fields = {TYPE: AMQPTypes.map, VALUE: []} for key, data in value.items(): - if key == b'com.microsoft:timeout': - data = {'TYPE': AMQPTypes.uint, 'VALUE': data} if isinstance(key, str): key = key.encode("utf-8") # type: ignore cast(List, fields[VALUE]).append(({TYPE: AMQPTypes.symbol, VALUE: key}, data)) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 541d43d0fa98..13e47619c28b 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -66,6 +66,7 @@ ERROR_CODE_ENTITY_ALREADY_EXISTS, ERROR_CODE_PRECONDITION_FAILED, ServiceBusReceiveMode, + OPERATION_TIMEOUT, ) from ..exceptions import ( @@ -576,6 +577,14 @@ def create_receive_client( config = receiver._config # pylint: disable=protected-access source = kwargs.pop("source") receive_mode = kwargs.pop("receive_mode") + link_properties = kwargs.pop("link_properties") + + # If we have specified a client-side timeout, assure that it is encoded as an uint + if link_properties[OPERATION_TIMEOUT]: + link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) + + kwargs.update(link_properties=link_properties) + return ReceiveClient( config.hostname, source, diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index fac721d810b8..cccde91ce1cd 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -10,7 +10,7 @@ from ..._pyamqp import constants from ..._pyamqp.message import BatchMessage -from ..._pyamqp.utils import amqp_string_value +from ..._pyamqp.utils import amqp_string_value, amqp_uint_value from ..._pyamqp.aio import SendClientAsync, ReceiveClientAsync from ..._pyamqp.aio._authentication_async import JWTTokenAuthAsync from ..._pyamqp.aio._connection_async import Connection as ConnectionAsync @@ -35,6 +35,7 @@ MESSAGE_DEFER, MESSAGE_DEAD_LETTER, ServiceBusReceiveMode, + OPERATION_TIMEOUT, ) from ..._transport._pyamqp_transport import PyamqpTransport from ...exceptions import ( @@ -179,6 +180,13 @@ def create_receive_client_async( config = receiver._config # pylint: disable=protected-access source = kwargs.pop("source") receive_mode = kwargs.pop("receive_mode") + link_properties = kwargs.pop("link_properties") + + # If we have specified a client-side timeout, assure that it is encoded as an uint + if link_properties[OPERATION_TIMEOUT]: + link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) + + kwargs.update(link_properties=link_properties) return ReceiveClientAsync( config.hostname, From e1a476228f906a13c42baa7e61ce2eb988618145 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 6 Jul 2023 15:44:02 -0700 Subject: [PATCH 06/50] update docstring --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 4 +++- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 54405240fcca..01a903ddde93 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -110,7 +110,9 @@ class ServiceBusReceiver( :keyword str subscription_name: The path of specific Service Bus Subscription under the specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. + receiver will automatically stop receiving. The default value is None, meaning no timeout. + If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, + max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 60ea72b446fd..6425d1e6c3dd 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -121,6 +121,8 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. + If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, + max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. From 66a8d8aba3cd6d3ad087cb0c5dadc83cfac789da Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 6 Jul 2023 15:52:40 -0700 Subject: [PATCH 07/50] add tests --- .../tests/async_tests/test_sessions_async.py | 22 ++++++++++++++++++- .../azure-servicebus/tests/test_sessions.py | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py index 98f33b42d537..fd0c5c5b040b 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py @@ -1170,4 +1170,24 @@ async def test_async_session_non_session_send_to_session_queue_should_fail(self, async with sb_client.get_queue_sender(servicebus_queue.name) as sender: with pytest.raises(ServiceBusError): message = ServiceBusMessage("Handler message") - await sender.send_messages(message) \ No newline at end of file + await sender.send_messages(message) + + @pytest.mark.asyncio + @pytest.mark.liveTest + @pytest.mark.live_test_only + @CachedServiceBusResourceGroupPreparer(name_prefix='servicebustest') + @CachedServiceBusNamespacePreparer(name_prefix='servicebustest') + @ServiceBusQueuePreparer(name_prefix='servicebustest', requires_session=True) + @pytest.mark.parametrize("uamqp_transport", uamqp_transport_params, ids=uamqp_transport_ids) + @ArgPasserAsync() + async def test_async_session_by_session_client_conn_str_receive_handler_with_no_session(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): + if uamqp_transport==True: + pytest.skip("This test is for pyamqp only") + async with ServiceBusClient.from_connection_string( + servicebus_namespace_connection_string, logging_enable=False, uamqp_transport=uamqp_transport) as sb_client: + + receiver = sb_client.get_queue_receiver(servicebus_queue.name, session_id=NEXT_AVAILABLE_SESSION, max_wait_time=10) + start_time = time.time() + with pytest.raises(OperationTimeoutError): + await receiver._open_with_retry() + assert time.time() - start_time < 65 # Default service timeout value is 65 seconds \ No newline at end of file diff --git a/sdk/servicebus/azure-servicebus/tests/test_sessions.py b/sdk/servicebus/azure-servicebus/tests/test_sessions.py index 494e85ec2b3e..01439e9e21e5 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sessions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sessions.py @@ -1327,3 +1327,25 @@ def test_session_id_str_bytes(self, uamqp_transport, *, servicebus_namespace_con messages = receiver.receive_messages(max_wait_time=10) assert len(messages) == 1 assert messages[0].session_id == session_id + + + @pytest.mark.liveTest + @pytest.mark.live_test_only + @CachedServiceBusResourceGroupPreparer(name_prefix='servicebustest') + @CachedServiceBusNamespacePreparer(name_prefix='servicebustest') + @ServiceBusQueuePreparer(name_prefix='servicebustest', requires_session=True) + @pytest.mark.parametrize("uamqp_transport", uamqp_transport_params, ids=uamqp_transport_ids) + @ArgPasser() + def test_next_available_session_timeout_value(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): + if uamqp_transport==True: + pytest.skip("This test is for pyamqp only") + with ServiceBusClient.from_connection_string( + servicebus_namespace_connection_string, logging_enable=False, uamqp_transport=uamqp_transport, retry_total=1) as sb_client: + start_time = time.time() + with pytest.raises(OperationTimeoutError): + with sb_client.get_queue_receiver(servicebus_queue.name, + session_id=NEXT_AVAILABLE_SESSION, + max_wait_time=10,) as session: + pass + end_time = time.time() + assert end_time - start_time < 65 # Default service operation timeout is 65 seconds From 84497242c9e8e5db739f5fd470c3504ce751269e Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 08:28:29 -0700 Subject: [PATCH 08/50] update if statement --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 4 +--- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 01a903ddde93..8f958e2be1a3 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -5,8 +5,6 @@ # pylint:disable=too-many-lines import threading import time -import math -import random import logging import functools import uuid @@ -350,7 +348,7 @@ def _from_connection_string( def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth"]) -> None: link_properties = {CONSUMER_IDENTIFIER: self._name} - if self._session._session_id == NEXT_AVAILABLE_SESSION: + if self._session_id == NEXT_AVAILABLE_SESSION: timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 # open_receive_link_base_jitter_in_ms = 100 # open_recieve_link_buffer_in_ms = 20 diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 6425d1e6c3dd..cc6746aec680 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -346,7 +346,7 @@ def _from_connection_string( def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTTokenAuthAsync"]) -> None: link_properties = {CONSUMER_IDENTIFIER: self._name} - if self._session._session_id == NEXT_AVAILABLE_SESSION: + if self._session_id == NEXT_AVAILABLE_SESSION: timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 # open_receive_link_base_jitter_in_ms = 100 # open_recieve_link_buffer_in_ms = 20 From 91b58cbc77a1bb66661d9e554e814def7cd4dc0b Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 08:40:52 -0700 Subject: [PATCH 09/50] update if statements --- .../azure/servicebus/_transport/_pyamqp_transport.py | 2 +- .../azure/servicebus/aio/_transport/_pyamqp_transport_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 13e47619c28b..da4edf8c4514 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -580,7 +580,7 @@ def create_receive_client( link_properties = kwargs.pop("link_properties") # If we have specified a client-side timeout, assure that it is encoded as an uint - if link_properties[OPERATION_TIMEOUT]: + if link_properties.get(OPERATION_TIMEOUT, None): link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) kwargs.update(link_properties=link_properties) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index cccde91ce1cd..a13dbce4f3b6 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -183,7 +183,7 @@ def create_receive_client_async( link_properties = kwargs.pop("link_properties") # If we have specified a client-side timeout, assure that it is encoded as an uint - if link_properties[OPERATION_TIMEOUT]: + if link_properties.get(OPERATION_TIMEOUT, None): link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) kwargs.update(link_properties=link_properties) From d53386b1c876ba60b932a246a4837c972c013984 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 08:42:04 -0700 Subject: [PATCH 10/50] whitespace --- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index cc6746aec680..9a4bb42c0e48 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -121,7 +121,7 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, + If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with From 4e28e4f791a994bf2956a5259afe4b9c3696191f Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 09:19:18 -0700 Subject: [PATCH 11/50] trailing whitespace --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 8f958e2be1a3..70f98718c51f 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -108,8 +108,8 @@ class ServiceBusReceiver( :keyword str subscription_name: The path of specific Service Bus Subscription under the specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, + receiver will automatically stop receiving. The default value is None, meaning no timeout. + If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given From 647aa6ebfeaf327d56122b5eed91444a78e59c10 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 10:45:05 -0700 Subject: [PATCH 12/50] move logic into pyamqp_transport --- .../azure/servicebus/_servicebus_receiver.py | 15 +-------------- .../servicebus/_transport/_pyamqp_transport.py | 16 +++++++++++++--- .../servicebus/aio/_servicebus_receiver_async.py | 15 +-------------- .../aio/_transport/_pyamqp_transport_async.py | 16 +++++++++++++--- .../tests/async_tests/test_sessions_async.py | 11 ++++++++--- .../azure-servicebus/tests/test_sessions.py | 15 ++++++++++----- 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 70f98718c51f..6b618db4dc71 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -47,8 +47,6 @@ MGMT_REQUEST_DEAD_LETTER_REASON, MGMT_REQUEST_DEAD_LETTER_ERROR_DESCRIPTION, MGMT_RESPONSE_MESSAGE_EXPIRATION, - OPERATION_TIMEOUT, - NEXT_AVAILABLE_SESSION ) from ._common import mgmt_handlers from ._common.receiver_mixins import ReceiverMixin @@ -347,17 +345,6 @@ def _from_connection_string( return cls(**constructor_args) def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth"]) -> None: - link_properties = {CONSUMER_IDENTIFIER: self._name} - if self._session_id == NEXT_AVAILABLE_SESSION: - timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 - # open_receive_link_base_jitter_in_ms = 100 - # open_recieve_link_buffer_in_ms = 20 - # open_receive_link_buffer_threshold_in_ms = 1000 - # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) - # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) - # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: - # timeout_in_ms -= open_recieve_link_buffer_in_ms - link_properties[OPERATION_TIMEOUT] = timeout_in_ms - 100 self._handler = self._amqp_transport.create_receive_client( receiver=self, @@ -379,7 +366,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuth", "uamqp_JWTTokenAuth if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties=link_properties, + link_properties={CONSUMER_IDENTIFIER: self._name}, ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index da4edf8c4514..e42fc903ce2e 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -67,6 +67,7 @@ ERROR_CODE_PRECONDITION_FAILED, ServiceBusReceiveMode, OPERATION_TIMEOUT, + NEXT_AVAILABLE_SESSION, ) from ..exceptions import ( @@ -579,9 +580,18 @@ def create_receive_client( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - # If we have specified a client-side timeout, assure that it is encoded as an uint - if link_properties.get(OPERATION_TIMEOUT, None): - link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) + if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: + timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) + # open_receive_link_base_jitter_in_ms = 100 + # open_recieve_link_buffer_in_ms = 20 + # open_receive_link_buffer_threshold_in_ms = 1000 + # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + # timeout_in_ms -= open_recieve_link_buffer_in_ms + + # If we have specified a client-side timeout, assure that it is encoded as an uint + link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) kwargs.update(link_properties=link_properties) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 9a4bb42c0e48..685a0d67760e 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -49,8 +49,6 @@ MGMT_REQUEST_DEAD_LETTER_REASON, MGMT_REQUEST_DEAD_LETTER_ERROR_DESCRIPTION, MGMT_RESPONSE_MESSAGE_EXPIRATION, - OPERATION_TIMEOUT, - NEXT_AVAILABLE_SESSION ) from .._common import mgmt_handlers from .._common.utils import utc_from_timestamp @@ -345,17 +343,6 @@ def _from_connection_string( return cls(**constructor_args) def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTTokenAuthAsync"]) -> None: - link_properties = {CONSUMER_IDENTIFIER: self._name} - if self._session_id == NEXT_AVAILABLE_SESSION: - timeout_in_ms = self._max_wait_time * 1000 if self._max_wait_time else 0 - # open_receive_link_base_jitter_in_ms = 100 - # open_recieve_link_buffer_in_ms = 20 - # open_receive_link_buffer_threshold_in_ms = 1000 - # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) - # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) - # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: - # timeout_in_ms -= open_recieve_link_buffer_in_ms - link_properties[OPERATION_TIMEOUT] = timeout_in_ms - 100 self._handler = self._amqp_transport.create_receive_client_async( receiver=self, @@ -377,7 +364,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTToke if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties = link_properties + link_properties = {CONSUMER_IDENTIFIER: self._name} ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index a13dbce4f3b6..278fe2daba30 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -36,6 +36,7 @@ MESSAGE_DEAD_LETTER, ServiceBusReceiveMode, OPERATION_TIMEOUT, + NEXT_AVAILABLE_SESSION, ) from ..._transport._pyamqp_transport import PyamqpTransport from ...exceptions import ( @@ -182,9 +183,18 @@ def create_receive_client_async( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - # If we have specified a client-side timeout, assure that it is encoded as an uint - if link_properties.get(OPERATION_TIMEOUT, None): - link_properties[OPERATION_TIMEOUT] = amqp_uint_value(link_properties[OPERATION_TIMEOUT]) + if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: + timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) + # open_receive_link_base_jitter_in_ms = 100 + # open_recieve_link_buffer_in_ms = 20 + # open_receive_link_buffer_threshold_in_ms = 1000 + # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + # timeout_in_ms -= open_recieve_link_buffer_in_ms + + # If we have specified a client-side timeout, assure that it is encoded as an uint + link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) kwargs.update(link_properties=link_properties) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py index fd0c5c5b040b..0dcbab69a3c6 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py @@ -1180,7 +1180,7 @@ async def test_async_session_non_session_send_to_session_queue_should_fail(self, @ServiceBusQueuePreparer(name_prefix='servicebustest', requires_session=True) @pytest.mark.parametrize("uamqp_transport", uamqp_transport_params, ids=uamqp_transport_ids) @ArgPasserAsync() - async def test_async_session_by_session_client_conn_str_receive_handler_with_no_session(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): + async def test_async_next_available_session_timeout_value(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): if uamqp_transport==True: pytest.skip("This test is for pyamqp only") async with ServiceBusClient.from_connection_string( @@ -1189,5 +1189,10 @@ async def test_async_session_by_session_client_conn_str_receive_handler_with_no_ receiver = sb_client.get_queue_receiver(servicebus_queue.name, session_id=NEXT_AVAILABLE_SESSION, max_wait_time=10) start_time = time.time() with pytest.raises(OperationTimeoutError): - await receiver._open_with_retry() - assert time.time() - start_time < 65 # Default service timeout value is 65 seconds \ No newline at end of file + await receiver.receive_messages(max_wait_time=5) + assert time.time() - start_time < 65 # Default service timeout value is 65 seconds + start_time2 = time.time() + with pytest.raises(OperationTimeoutError): + async for msg in receiver: + pass + assert time.time() - start_time2 < 65 # Default service timeout value is 65 seconds \ No newline at end of file diff --git a/sdk/servicebus/azure-servicebus/tests/test_sessions.py b/sdk/servicebus/azure-servicebus/tests/test_sessions.py index 01439e9e21e5..45ed83fa251e 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sessions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sessions.py @@ -1341,11 +1341,16 @@ def test_next_available_session_timeout_value(self, uamqp_transport, *, serviceb pytest.skip("This test is for pyamqp only") with ServiceBusClient.from_connection_string( servicebus_namespace_connection_string, logging_enable=False, uamqp_transport=uamqp_transport, retry_total=1) as sb_client: + + receiver = sb_client.get_queue_receiver(servicebus_queue.name, session_id=NEXT_AVAILABLE_SESSION, max_wait_time=10,) + start_time = time.time() with pytest.raises(OperationTimeoutError): - with sb_client.get_queue_receiver(servicebus_queue.name, - session_id=NEXT_AVAILABLE_SESSION, - max_wait_time=10,) as session: + receiver.receive_messages(max_wait_time=5) + assert time.time() - start_time < 65 # Default service operation timeout is 65 seconds + start_time2 = time.time() + with pytest.raises(OperationTimeoutError): + for msg in receiver: pass - end_time = time.time() - assert end_time - start_time < 65 # Default service operation timeout is 65 seconds + + assert time.time() - start_time2 < 65 # Default service operation timeout is 65 seconds From f03df027c317a96a801e9731108aff68d4732adf Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Fri, 7 Jul 2023 13:04:21 -0700 Subject: [PATCH 13/50] pylint --- .../azure/servicebus/_transport/_pyamqp_transport.py | 4 ++-- .../servicebus/aio/_transport/_pyamqp_transport_async.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index e42fc903ce2e..04011b53b37e 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -580,8 +580,8 @@ def create_receive_client( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: - timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) + if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access + timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access # open_receive_link_base_jitter_in_ms = 100 # open_recieve_link_buffer_in_ms = 20 # open_receive_link_buffer_threshold_in_ms = 1000 diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index 278fe2daba30..cc3677333d75 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -183,8 +183,8 @@ def create_receive_client_async( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: - timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) + if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access + timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access # open_receive_link_base_jitter_in_ms = 100 # open_recieve_link_buffer_in_ms = 20 # open_receive_link_buffer_threshold_in_ms = 1000 From 2aee2f9a7fbe4ae6799f2d328368c229f2e12901 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Mon, 10 Jul 2023 12:38:14 -0700 Subject: [PATCH 14/50] update kwargs --- .../azure/servicebus/_transport/_pyamqp_transport.py | 2 +- .../azure/servicebus/aio/_transport/_pyamqp_transport_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 04011b53b37e..374d93de03f0 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -593,7 +593,7 @@ def create_receive_client( # If we have specified a client-side timeout, assure that it is encoded as an uint link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) - kwargs.update(link_properties=link_properties) + kwargs["link_properties"] = link_properties return ReceiveClient( config.hostname, diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index cc3677333d75..ed7367670f21 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -196,7 +196,7 @@ def create_receive_client_async( # If we have specified a client-side timeout, assure that it is encoded as an uint link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) - kwargs.update(link_properties=link_properties) + kwargs["link_properties"] = link_properties return ReceiveClientAsync( config.hostname, From 1be333a79b15a2fddcc74ba5e032113735003d29 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Tue, 25 Jul 2023 12:40:26 -0700 Subject: [PATCH 15/50] Update sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py Co-authored-by: Kashif Khan <361477+kashifkhan@users.noreply.github.com> --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 6b618db4dc71..5a2421fed661 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -107,8 +107,8 @@ class ServiceBusReceiver( specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, - max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. + If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, + max_wait_time will wait for that time to receive a message from any session before the operations times out. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE From ef0a3eb6ca6b9af3a8d233ea15fb60763809c025 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 25 Jul 2023 13:31:46 -0700 Subject: [PATCH 16/50] update async docstring too --- .../azure/servicebus/aio/_servicebus_receiver_async.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 685a0d67760e..d1a31e241d1a 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -119,8 +119,8 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is a sessionful queue or topic and NEXT_AVAILABLE_SESSION is specified, - max_wait_time will replace the server-side operation timeout when waiting on connecting to a session. + If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, + max_wait_time will wait for that time to receive a message from any session before the operations times out. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. From 70023edb37645bc41fb58a0458ebad7c2bfe3abd Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 1 Aug 2023 10:00:39 -0700 Subject: [PATCH 17/50] update docstrings --- .../azure/servicebus/_servicebus_client.py | 8 ++++++-- .../azure/servicebus/_servicebus_receiver.py | 2 -- .../azure/servicebus/aio/_servicebus_client_async.py | 8 ++++++-- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 -- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 7306f002b61f..91c47cb9939e 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -359,7 +359,9 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any + session before the operations times out. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -549,7 +551,9 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any + session before the operations times out. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 5a2421fed661..a3635c007aa3 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -107,8 +107,6 @@ class ServiceBusReceiver( specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, - max_wait_time will wait for that time to receive a message from any session before the operations times out. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index 32fb1576eb66..6b54ff4a6e25 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -344,7 +344,9 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any + session before the operations times out. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -523,7 +525,9 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any + session before the operations times out. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index d1a31e241d1a..889e146b9e6c 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -119,8 +119,6 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. - If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, - max_wait_time will wait for that time to receive a message from any session before the operations times out. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. From fb63534fcd1184cf72e888499ca2c91da78088ce Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 1 Aug 2023 10:21:36 -0700 Subject: [PATCH 18/50] add back in jitter logic to align with other lang --- .../servicebus/_transport/_pyamqp_transport.py | 18 ++++++++++-------- .../aio/_transport/_pyamqp_transport_async.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 374d93de03f0..df4e2f3d2020 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -5,6 +5,8 @@ # pylint: disable=too-many-lines import functools import time +import math +import random import datetime from datetime import timezone from typing import Optional, Tuple, cast, List, TYPE_CHECKING, Any, Callable, Dict, Union, Iterator, Type @@ -581,14 +583,14 @@ def create_receive_client( link_properties = kwargs.pop("link_properties") if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access - timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access - # open_receive_link_base_jitter_in_ms = 100 - # open_recieve_link_buffer_in_ms = 20 - # open_receive_link_buffer_threshold_in_ms = 1000 - # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) - # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) - # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: - # timeout_in_ms -= open_recieve_link_buffer_in_ms + timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access + open_receive_link_base_jitter_in_ms = 100 + open_recieve_link_buffer_in_ms = 20 + open_receive_link_buffer_threshold_in_ms = 1000 + jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + timeout_in_ms -= open_recieve_link_buffer_in_ms # If we have specified a client-side timeout, assure that it is encoded as an uint link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index ed7367670f21..cb6790067df2 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -7,6 +7,8 @@ import functools from typing import TYPE_CHECKING, Optional, Any, Callable, Union, AsyncIterator, cast import time +import math +import random from ..._pyamqp import constants from ..._pyamqp.message import BatchMessage @@ -184,14 +186,14 @@ def create_receive_client_async( link_properties = kwargs.pop("link_properties") if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access - timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access - # open_receive_link_base_jitter_in_ms = 100 - # open_recieve_link_buffer_in_ms = 20 - # open_receive_link_buffer_threshold_in_ms = 1000 - # jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) - # timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) - # if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: - # timeout_in_ms -= open_recieve_link_buffer_in_ms + timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access + open_receive_link_base_jitter_in_ms = 100 + open_recieve_link_buffer_in_ms = 20 + open_receive_link_buffer_threshold_in_ms = 1000 + jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms) + timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random()) + if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms: + timeout_in_ms -= open_recieve_link_buffer_in_ms # If we have specified a client-side timeout, assure that it is encoded as an uint link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms) From 21f69a57bb1d6990c4e72c66d8905b4afcb26e32 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Mon, 2 Oct 2023 13:36:16 -0700 Subject: [PATCH 19/50] update client wording --- .../azure-servicebus/azure/servicebus/_servicebus_client.py | 4 ++-- .../azure/servicebus/aio/_servicebus_client_async.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 91c47cb9939e..ca51e199d982 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -552,8 +552,8 @@ def get_subscription_receiver( receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any - session before the operations times out. + NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to + receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index 6b54ff4a6e25..d5dc3cd96226 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -526,8 +526,8 @@ def get_subscription_receiver( receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any - session before the operations times out. + NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to + receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. From 63697ee204647a298c8c3a69992010510174d3cf Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Mon, 2 Oct 2023 13:38:58 -0700 Subject: [PATCH 20/50] update other receiver docstring --- .../azure-servicebus/azure/servicebus/_servicebus_client.py | 4 ++-- .../azure/servicebus/aio/_servicebus_client_async.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index ca51e199d982..a2b14135e8bb 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -360,8 +360,8 @@ def get_queue_receiver( receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any - session before the operations times out. + NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to + receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index d5dc3cd96226..5450c31a7a84 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -345,8 +345,8 @@ def get_queue_receiver( receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, max_wait_time will wait for that time to receive a message from any - session before the operations times out. + NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to + receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. From 5baf6f90f8c54fc431b08271caec5f472aecdf03 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Mon, 2 Oct 2023 13:42:08 -0700 Subject: [PATCH 21/50] remove spacing --- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 889e146b9e6c..74311b4ccf32 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -362,7 +362,7 @@ def _create_handler(self, auth: Union["pyamqp_JWTTokenAuthAsync", "uamqp_JWTToke if self._prefetch_count != 0 else 5, shutdown_after_timeout=False, - link_properties = {CONSUMER_IDENTIFIER: self._name} + link_properties = {CONSUMER_IDENTIFIER:self._name} ) # When prefetch is 0 and receive mode is PEEK_LOCK, release messages when they're received. # This will stop messages from expiring in the buffer and incrementing delivery count of a message. From d08d92830ea4dc2a7d310c9e3168b7c4f9e991de Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 3 Oct 2023 09:30:12 -0700 Subject: [PATCH 22/50] pylint --- .../azure-servicebus/azure/servicebus/_servicebus_client.py | 4 ++-- .../azure/servicebus/aio/_servicebus_client_async.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index a2b14135e8bb..aad8f749b184 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -359,7 +359,7 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer @@ -551,7 +551,7 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index 5450c31a7a84..2247f0392713 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -344,7 +344,7 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An @@ -525,7 +525,7 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An From 8f10e07d9d058ef09342e8de575d38219d56c965 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 Oct 2023 10:51:41 -0700 Subject: [PATCH 23/50] add comment --- .../azure/servicebus/_transport/_pyamqp_transport.py | 4 ++++ .../servicebus/aio/_transport/_pyamqp_transport_async.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index df4e2f3d2020..7688d1063af7 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -582,6 +582,10 @@ def create_receive_client( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") + # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. + # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame frame from the service from a session + # before raising an OperationTimeoutError due to failure to connect. max_wait_time, if specified, will allow the user to wait for fewer + # than 65 seconds to connect to a session. if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access open_receive_link_base_jitter_in_ms = 100 diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index cb6790067df2..bdacbbc76841 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -185,6 +185,10 @@ def create_receive_client_async( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") + # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. + # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame frame from the service from a session + # before raising an OperationTimeoutError due to failure to connect. max_wait_time, if specified, will allow the user to wait for fewer + # than 65 seconds to connect to a session. if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access open_receive_link_base_jitter_in_ms = 100 From 87a7f4e5c532918109478ab2ecafcab57019b478 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 Oct 2023 12:21:07 -0700 Subject: [PATCH 24/50] update client --- .../azure/servicebus/_servicebus_client.py | 20 +++++++++++-------- .../aio/_servicebus_client_async.py | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index aad8f749b184..1ba838f8da90 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -356,10 +356,12 @@ def get_queue_receiver( will be immediately removed from the queue, and cannot be subsequently rejected or re-received if the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection - errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, + and no timeout is specified, this call will not return until the connection is closed. + The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, + the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer @@ -548,10 +550,12 @@ def get_subscription_receiver( will be immediately removed from the subscription, and cannot be subsequently rejected or re-received if the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection - errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, + and no timeout is specified, this call will not return until the connection is closed. + The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, + the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index 2247f0392713..c6ccf66e3f70 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -341,10 +341,12 @@ def get_queue_receiver( will be immediately removed from the queue, and cannot be subsequently rejected or re-received if the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection - errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, + and no timeout is specified, this call will not return until the connection is closed. + The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, + the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An @@ -522,10 +524,12 @@ def get_subscription_receiver( will be immediately removed from the subscription, and cannot be subsequently rejected or re-received if the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection - errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See - the `socket_timeout` optional parameter for more details. If there is session enabled queue or topic and + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, + and no timeout is specified, this call will not return until the connection is closed. + The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, + the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. If there is session enabled queue or topic and NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to receive a message from any session. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An From 5e786002561089291502bd1172d7e68ffb6bffad Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Mon, 30 Oct 2023 08:19:13 -0700 Subject: [PATCH 25/50] fix pylint --- .../azure/servicebus/_transport/_pyamqp_transport.py | 9 +++++---- .../servicebus/aio/_transport/_pyamqp_transport_async.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 7688d1063af7..5de18f2a1217 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -582,10 +582,11 @@ def create_receive_client( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. - # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame frame from the service from a session - # before raising an OperationTimeoutError due to failure to connect. max_wait_time, if specified, will allow the user to wait for fewer - # than 65 seconds to connect to a session. + # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. + # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame + # frame from the service before raising an OperationTimeoutError due to failure to connect. + # max_wait_time, if specified, will allow the user to wait for fewer or more than 65 seconds to + # connect to a session. if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access open_receive_link_base_jitter_in_ms = 100 diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index bdacbbc76841..eb5c9cfddb20 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -185,10 +185,11 @@ def create_receive_client_async( receive_mode = kwargs.pop("receive_mode") link_properties = kwargs.pop("link_properties") - # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. - # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame frame from the service from a session - # before raising an OperationTimeoutError due to failure to connect. max_wait_time, if specified, will allow the user to wait for fewer - # than 65 seconds to connect to a session. + # When NEXT_AVAILABLE_SESSION is set, the default time to wait to connect to a session is 65 seconds. + # If there are no messages in the topic/queue the client will wait for 65 seconds for an AttachFrame + # frame from the service before raising an OperationTimeoutError due to failure to connect. + # max_wait_time, if specified, will allow the user to wait for fewer or more than 65 seconds to + # connect to a session. if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access open_receive_link_base_jitter_in_ms = 100 From c2a83e739291c1da2f1b79a65782cef02a53e17c Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 18 Jan 2024 12:23:53 -0800 Subject: [PATCH 26/50] update max_wait_time docstring --- .../azure/servicebus/_servicebus_client.py | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 1ba838f8da90..4184a578873f 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -357,13 +357,12 @@ def get_queue_receiver( the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, - and no timeout is specified, this call will not return until the connection is closed. - The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, - the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to - receive a message from any session. + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -551,13 +550,12 @@ def get_subscription_receiver( the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, - and no timeout is specified, this call will not return until the connection is closed. - The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, - the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to - receive a message from any session. + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. From 51f066f54be9f2a43cb9c4fad33cc1165749300f Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 18 Jan 2024 12:24:06 -0800 Subject: [PATCH 27/50] align iterator and receive_messages() behavior --- .../azure/servicebus/_servicebus_receiver.py | 33 ++++++++++++++----- .../_transport/_pyamqp_transport.py | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index a3635c007aa3..456c9e149fe4 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -105,8 +105,13 @@ class ServiceBusReceiver( the client connects to. :keyword str subscription_name: The path of specific Service Bus Subscription under the specified Topic the client connects to. - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE @@ -258,7 +263,12 @@ def _inner_next( self._check_live() while True: try: - return self._do_retryable_operation(self._iter_next, wait_time=wait_time) + return self._do_retryable_operation( + self._iter_next, + wait_time=wait_time, + timeout=self._max_wait_time, + operation_requires_timeout=True + ) except StopIteration: self._message_iter = None raise @@ -296,8 +306,13 @@ def _from_connection_string( if the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. @@ -666,10 +681,10 @@ def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. - If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. If specified, an no messages arrive within the - timeout period, an empty list will be returned. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: List[~azure.servicebus.ServiceBusReceivedMessage] diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 5de18f2a1217..232fd7d7ff44 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -671,7 +671,7 @@ def iter_contextual_wrapper( @staticmethod def iter_next( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs ) -> "ServiceBusReceivedMessage": """ Used to iterate through received messages. From 6a6427224f8abaecca4395fae68ac22d184f35ce Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 18 Jan 2024 12:29:08 -0800 Subject: [PATCH 28/50] docstring updates --- .../azure/servicebus/_servicebus_receiver.py | 4 +-- .../aio/_servicebus_client_async.py | 26 +++++++++---------- .../aio/_servicebus_receiver_async.py | 15 ++++++----- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 456c9e149fe4..a9a42fbc24e7 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -310,9 +310,7 @@ def _from_connection_string( messages to arrive, or the total time for the operation to complete. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + this will act as the timeout for connecting to a session. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index c6ccf66e3f70..57de37e7c9ea 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -342,13 +342,12 @@ def get_queue_receiver( the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, - and no timeout is specified, this call will not return until the connection is closed. - The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, - the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to - receive a message from any session. + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -525,13 +524,12 @@ def get_subscription_receiver( the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive after which the receiver will automatically stop receiving. If no messages arrive, - and no timeout is specified, this call will not return until the connection is closed. - The default value is None, meaning no timeout. If connection errors are occurring due to write timing out, - the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. If there is session enabled queue or topic and - NEXT_AVAILABLE_SESSION is specified, operation will time out after waiting `max_wait_time` seconds to - receive a message from any session. + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. If connection errors are occurring due + to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` + optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 74311b4ccf32..212327738a45 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -117,8 +117,11 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): if the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver - will automatically stop receiving. The default value is None, meaning no timeout. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, + this will act as the timeout for connecting to a session. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. @@ -646,10 +649,10 @@ async def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count size and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. - If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. If specified, and no messages arrive within the - timeout period, an empty list will be returned. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive, or the total time for the operation to complete. If no messages arrive, and no + timeout is specified, this call will not return until the connection is closed. The default value + is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: list[~azure.servicebus.aio.ServiceBusReceivedMessage] From 21d33fe49d1da2e0b31d09f1ac1601a2651a9cd3 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 18 Jan 2024 12:33:23 -0800 Subject: [PATCH 29/50] asyn align iterator and receive_messages() --- .../azure/servicebus/aio/_servicebus_receiver_async.py | 7 ++++++- .../servicebus/aio/_transport/_pyamqp_transport_async.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 212327738a45..2cc8743eb5ca 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -263,7 +263,12 @@ async def _inner_anext(self, wait_time: Optional[float] = None) -> ServiceBusRec self._check_live() while True: try: - return await self._do_retryable_operation(self._iter_next, wait_time=wait_time) + return await self._do_retryable_operation( + self._iter_next, + wait_time=wait_time, + timeout=self._max_wait_time, + operation_requires_timeout=True + ) except StopAsyncIteration: self._message_iter = None raise diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index eb5c9cfddb20..1fe50a07981a 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -240,7 +240,7 @@ async def iter_contextual_wrapper_async( @staticmethod async def iter_next_async( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs ) -> "ServiceBusReceivedMessage": # pylint: disable=protected-access try: From 3579629630d3013ab7e5f39d967fd579e1193bff Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 18 Jan 2024 14:12:18 -0800 Subject: [PATCH 30/50] add deprecation --- .../azure/servicebus/_servicebus_receiver.py | 9 +++++---- .../azure/servicebus/aio/_servicebus_receiver_async.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index a9a42fbc24e7..363e83021360 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -679,10 +679,11 @@ def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. + :keyword Optional[float] max_wait_time: DEPRECATED. Please use the max_wait_time + on the ServiceBusReceiver. The timeout in seconds to wait for the first and + subsequent messages to arrive, or the total time for the operation to complete. + If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: List[~azure.servicebus.ServiceBusReceivedMessage] diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 2cc8743eb5ca..0aa00c6437eb 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -654,10 +654,11 @@ async def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count size and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. + :keyword Optional[float] max_wait_time: DEPRECATED. Please use the max_wait_time + on the ServiceBusReceiver. The timeout in seconds to wait for the first and + subsequent messages to arrive, or the total time for the operation to complete. + If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: list[~azure.servicebus.aio.ServiceBusReceivedMessage] From 94ae2a6423826a9aa9096952c1de2b00980b464e Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 19 Jan 2024 11:03:25 -0800 Subject: [PATCH 31/50] pylint fixes --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 2 +- .../azure/servicebus/_transport/_pyamqp_transport.py | 2 +- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 +- .../azure/servicebus/aio/_transport/_pyamqp_transport_async.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 363e83021360..e41a00a5878c 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -679,7 +679,7 @@ def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :keyword Optional[float] max_wait_time: DEPRECATED. Please use the max_wait_time + :param Optional[float] max_wait_time: DEPRECATED - Please use the max_wait_time on the ServiceBusReceiver. The timeout in seconds to wait for the first and subsequent messages to arrive, or the total time for the operation to complete. If no messages arrive, and no timeout is specified, this call will not return diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 232fd7d7ff44..8dce27e4dc47 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -671,7 +671,7 @@ def iter_contextual_wrapper( @staticmethod def iter_next( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs # pylint: disable=unused-argument ) -> "ServiceBusReceivedMessage": """ Used to iterate through received messages. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 0aa00c6437eb..b22aeaf96e5c 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -654,7 +654,7 @@ async def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count size and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :keyword Optional[float] max_wait_time: DEPRECATED. Please use the max_wait_time + :param Optional[float] max_wait_time: DEPRECATED - Please use the max_wait_time on the ServiceBusReceiver. The timeout in seconds to wait for the first and subsequent messages to arrive, or the total time for the operation to complete. If no messages arrive, and no timeout is specified, this call will not return diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index 1fe50a07981a..04c3c80ca423 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -240,7 +240,7 @@ async def iter_contextual_wrapper_async( @staticmethod async def iter_next_async( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs # pylint: disable=unused-argument ) -> "ServiceBusReceivedMessage": # pylint: disable=protected-access try: From 9863d15c8cc7073861de2749164e7fb41db32455 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 19 Jan 2024 14:42:31 -0800 Subject: [PATCH 32/50] add timeout kwarg --- .../azure-servicebus/tests/async_tests/test_queues_async.py | 2 +- sdk/servicebus/azure-servicebus/tests/test_queues.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py index cfedf2ecbeca..f178b4941f9b 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py @@ -2620,7 +2620,7 @@ async def test_queue_async_send_dict_messages_scheduled_error_badly_formatted_di @ArgPasserAsync() async def test_queue_async_receive_iterator_resume_after_link_detach(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - async def hack_iter_next_mock_error(self, wait_time=None): + async def hack_iter_next_mock_error(self, wait_time=None, timeout=None): try: self._receive_context.set() await self._open() diff --git a/sdk/servicebus/azure-servicebus/tests/test_queues.py b/sdk/servicebus/azure-servicebus/tests/test_queues.py index e9b69c1a3e5a..d9d262c6cc60 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/test_queues.py @@ -3043,7 +3043,7 @@ def test_queue_send_dict_messages_scheduled_error_badly_formatted_dicts(self, ua @ArgPasser() def test_queue_receive_iterator_resume_after_link_detach(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - def hack_iter_next_mock_error(self, wait_time=None): + def hack_iter_next_mock_error(self, wait_time=None, timeout=None): try: self._receive_context.set() self._open() From b6eb85c67a41d8d05ff60f02caa88136c43d3439 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 24 Jan 2024 10:01:10 -0800 Subject: [PATCH 33/50] update docstring --- .../azure/servicebus/_servicebus_receiver.py | 16 ++++++---------- .../servicebus/aio/_servicebus_receiver_async.py | 14 ++++++-------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index e41a00a5878c..d9b05aa03330 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -106,12 +106,11 @@ class ServiceBusReceiver( :keyword str subscription_name: The path of specific Service Bus Subscription under the specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE @@ -266,8 +265,6 @@ def _inner_next( return self._do_retryable_operation( self._iter_next, wait_time=wait_time, - timeout=self._max_wait_time, - operation_requires_timeout=True ) except StopIteration: self._message_iter = None @@ -679,8 +676,7 @@ def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: DEPRECATED - Please use the max_wait_time - on the ServiceBusReceiver. The timeout in seconds to wait for the first and + :param Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive, or the total time for the operation to complete. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index b22aeaf96e5c..09eddd1f031f 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -118,10 +118,11 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. @@ -266,8 +267,6 @@ async def _inner_anext(self, wait_time: Optional[float] = None) -> ServiceBusRec return await self._do_retryable_operation( self._iter_next, wait_time=wait_time, - timeout=self._max_wait_time, - operation_requires_timeout=True ) except StopAsyncIteration: self._message_iter = None @@ -654,8 +653,7 @@ async def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count size and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: DEPRECATED - Please use the max_wait_time - on the ServiceBusReceiver. The timeout in seconds to wait for the first and + :param Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive, or the total time for the operation to complete. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. From b819c1df424d196a9a34629a69dd42db0d2d450d Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 24 Jan 2024 10:09:37 -0800 Subject: [PATCH 34/50] client docstring --- .../azure/servicebus/_servicebus_client.py | 22 +++++++++---------- .../aio/_servicebus_client_async.py | 22 +++++++++---------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 4184a578873f..fb9080ca41af 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -357,12 +357,11 @@ def get_queue_receiver( the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -550,12 +549,11 @@ def get_subscription_receiver( the client fails to process the message. The default receive_mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index 57de37e7c9ea..ad61f0e129b0 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -342,12 +342,11 @@ def get_queue_receiver( the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. @@ -524,12 +523,11 @@ def get_subscription_receiver( the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. If connection errors are occurring due - to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` - optional parameter for more details. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session receiver, it will apply to the session instead. From 92ba1a29be97d62d8d9429093ec2f6910fcb0351 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:09:43 -0800 Subject: [PATCH 35/50] add to OperationTimeoutError logic --- .../azure/servicebus/_base_handler.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py index ad8bc7c7b069..5be454be34ef 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py @@ -425,7 +425,16 @@ def _do_retryable_operation( self._container_id, last_exception, ) - raise last_exception from None + if isinstance(last_exception, OperationTimeoutError): + description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ + "use max_wait_time on the ServiceBusReceiver to control the"\ + " timeout when connecting to a session." + error = OperationTimeoutError( + message=description, + ) + raise error from last_exception + else: + raise last_exception from None self._backoff( retried_times=retried_times, last_exception=last_exception, @@ -461,6 +470,15 @@ def _backoff( entity_name, last_exception, ) + if isinstance(last_exception, OperationTimeoutError): + description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ + "use max_wait_time on the ServiceBusReceiver to control the"\ + " timeout when connecting to a session." + error = OperationTimeoutError( + message=description, + ) + + raise error from last_exception raise last_exception def _mgmt_request_response( From e5b940fbba1e2e5fbe6d808919fe93ff56c2c2a8 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:13:02 -0800 Subject: [PATCH 36/50] remove timeout from mock --- .../azure-servicebus/tests/async_tests/test_queues_async.py | 2 +- sdk/servicebus/azure-servicebus/tests/test_queues.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py index f178b4941f9b..cfedf2ecbeca 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py @@ -2620,7 +2620,7 @@ async def test_queue_async_send_dict_messages_scheduled_error_badly_formatted_di @ArgPasserAsync() async def test_queue_async_receive_iterator_resume_after_link_detach(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - async def hack_iter_next_mock_error(self, wait_time=None, timeout=None): + async def hack_iter_next_mock_error(self, wait_time=None): try: self._receive_context.set() await self._open() diff --git a/sdk/servicebus/azure-servicebus/tests/test_queues.py b/sdk/servicebus/azure-servicebus/tests/test_queues.py index d9d262c6cc60..e9b69c1a3e5a 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/test_queues.py @@ -3043,7 +3043,7 @@ def test_queue_send_dict_messages_scheduled_error_badly_formatted_dicts(self, ua @ArgPasser() def test_queue_receive_iterator_resume_after_link_detach(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - def hack_iter_next_mock_error(self, wait_time=None, timeout=None): + def hack_iter_next_mock_error(self, wait_time=None): try: self._receive_context.set() self._open() From e25204d72d1279aa4e6997d008fdd2b6aabe8b55 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:15:06 -0800 Subject: [PATCH 37/50] nit --- .../azure-servicebus/azure/servicebus/_base_handler.py | 3 +-- .../azure/servicebus/_transport/_pyamqp_transport.py | 2 +- .../azure/servicebus/aio/_transport/_pyamqp_transport_async.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py index 5be454be34ef..b1812cbf22da 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py @@ -433,8 +433,7 @@ def _do_retryable_operation( message=description, ) raise error from last_exception - else: - raise last_exception from None + raise last_exception from None self._backoff( retried_times=retried_times, last_exception=last_exception, diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py index 8dce27e4dc47..5de18f2a1217 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py @@ -671,7 +671,7 @@ def iter_contextual_wrapper( @staticmethod def iter_next( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs # pylint: disable=unused-argument + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None ) -> "ServiceBusReceivedMessage": """ Used to iterate through received messages. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py index 04c3c80ca423..eb5c9cfddb20 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py @@ -240,7 +240,7 @@ async def iter_contextual_wrapper_async( @staticmethod async def iter_next_async( - receiver: "ServiceBusReceiver", wait_time: Optional[int] = None, **kwargs # pylint: disable=unused-argument + receiver: "ServiceBusReceiver", wait_time: Optional[int] = None ) -> "ServiceBusReceivedMessage": # pylint: disable=protected-access try: From a6983955f015724a64123e5c8c2ca4797b8d9ca0 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:18:00 -0800 Subject: [PATCH 38/50] nit --- .../azure/servicebus/_servicebus_receiver.py | 5 +---- .../azure/servicebus/aio/_servicebus_receiver_async.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index d9b05aa03330..22f67603db34 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -262,10 +262,7 @@ def _inner_next( self._check_live() while True: try: - return self._do_retryable_operation( - self._iter_next, - wait_time=wait_time, - ) + return self._do_retryable_operation(self._iter_next, wait_time=wait_time) except StopIteration: self._message_iter = None raise diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 09eddd1f031f..49e715c0dcde 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -264,10 +264,7 @@ async def _inner_anext(self, wait_time: Optional[float] = None) -> ServiceBusRec self._check_live() while True: try: - return await self._do_retryable_operation( - self._iter_next, - wait_time=wait_time, - ) + return await self._do_retryable_operation(self._iter_next, wait_time=wait_time) except StopAsyncIteration: self._message_iter = None raise From cd1eaab99725708719af2c34d94e5189065a6576 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:21:40 -0800 Subject: [PATCH 39/50] revert doc --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 3 +-- .../azure/servicebus/aio/_servicebus_receiver_async.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 22f67603db34..371ffbb5b8b0 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -673,8 +673,7 @@ def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: The timeout in seconds to wait for the first and - subsequent messages to arrive, or the total time for the operation to complete. + :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 49e715c0dcde..88e2103b1e07 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -650,8 +650,7 @@ async def receive_messages( :param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number returned will depend on prefetch_count size and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1. - :param Optional[float] max_wait_time: The timeout in seconds to wait for the first and - subsequent messages to arrive, or the total time for the operation to complete. + :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. :return: A list of messages received. If no messages are available, this will be an empty list. From 096a2012ff2a1725efcac3efff5d1f88c4568e32 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:23:03 -0800 Subject: [PATCH 40/50] update error msg --- .../azure-servicebus/azure/servicebus/_base_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py index b1812cbf22da..76b8214cb998 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py @@ -428,7 +428,7 @@ def _do_retryable_operation( if isinstance(last_exception, OperationTimeoutError): description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ "use max_wait_time on the ServiceBusReceiver to control the"\ - " timeout when connecting to a session." + " timeout." error = OperationTimeoutError( message=description, ) @@ -472,7 +472,7 @@ def _backoff( if isinstance(last_exception, OperationTimeoutError): description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ "use max_wait_time on the ServiceBusReceiver to control the"\ - " timeout when connecting to a session." + " timeout." error = OperationTimeoutError( message=description, ) From a08c0045cdf11db90c453d98f5c6ae591141e73f Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 25 Jan 2024 15:24:58 -0800 Subject: [PATCH 41/50] nit --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 3 ++- .../azure/servicebus/aio/_servicebus_receiver_async.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 371ffbb5b8b0..0865435e8ce7 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -675,7 +675,8 @@ def receive_messages( Setting to None will fully depend on the prefetch config. The default value is 1. :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. + until the connection is closed. If specified, and no messages arrive within the + timeout period, an empty list will be returned. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: List[~azure.servicebus.ServiceBusReceivedMessage] diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 88e2103b1e07..17ba6e1f3974 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -652,7 +652,8 @@ async def receive_messages( Setting to None will fully depend on the prefetch config. The default value is 1. :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. + until the connection is closed. If specified, and no messages arrive within the + timeout period, an empty list will be returned. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: list[~azure.servicebus.aio.ServiceBusReceivedMessage] From 70059554cdd959749e51b5e283c74501a333fb46 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 26 Jan 2024 08:44:47 -0800 Subject: [PATCH 42/50] base handler async handling --- .../azure/servicebus/aio/_base_handler_async.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_base_handler_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_base_handler_async.py index b22328b04f24..727de125cd28 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_base_handler_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_base_handler_async.py @@ -274,6 +274,14 @@ async def _do_retryable_operation( self._container_id, last_exception, ) + if isinstance(last_exception, OperationTimeoutError): + description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ + "use max_wait_time on the ServiceBusReceiver to control the"\ + " timeout." + error = OperationTimeoutError( + message=description, + ) + raise error from last_exception raise last_exception from None await self._backoff( retried_times=retried_times, @@ -306,6 +314,14 @@ async def _backoff( entity_name, last_exception, ) + if isinstance(last_exception, OperationTimeoutError): + description = "If trying to receive from NEXT_AVAILABLE_SESSION, "\ + "use max_wait_time on the ServiceBusReceiver to control the"\ + " timeout." + error = OperationTimeoutError( + message=description, + ) + raise error from last_exception raise last_exception async def _mgmt_request_response( From ac50d446ab8cbc430d8ebcf2bbcb5e5753d89e9f Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 26 Jan 2024 09:00:09 -0800 Subject: [PATCH 43/50] doc --- .../azure/servicebus/_servicebus_client.py | 8 ++++---- .../azure/servicebus/aio/_servicebus_client_async.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index fb9080ca41af..18e3a0a1c840 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -359,8 +359,8 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. On a sessionful - queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting - to a session. If connection errors are occurring due to write timing out,the connection timeout + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. + If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session @@ -551,8 +551,8 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. On a sessionful - queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting - to a session. If connection errors are occurring due to write timing out,the connection timeout + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. + If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer can be provided such that messages are automatically registered on receipt. If the receiver is a session diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index ad61f0e129b0..dc686304cbac 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -344,8 +344,8 @@ def get_queue_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. On a sessionful - queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting - to a session. If connection errors are occurring due to write timing out,the connection timeout + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. + If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on @@ -525,8 +525,8 @@ def get_subscription_receiver( :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. The default value is None, meaning no timeout. On a sessionful - queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting - to a session. If connection errors are occurring due to write timing out,the connection timeout + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. + If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on From 26014a2bdddf41426e00e1bea218f00ee8270e48 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 26 Jan 2024 15:18:02 -0800 Subject: [PATCH 44/50] pylint --- .../azure-servicebus/azure/servicebus/_servicebus_client.py | 4 ++-- .../azure/servicebus/aio/_servicebus_client_async.py | 4 ++-- .../azure/servicebus/aio/_servicebus_receiver_async.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 18e3a0a1c840..262845606dab 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -358,7 +358,7 @@ def get_queue_receiver( :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. @@ -550,7 +550,7 @@ def get_subscription_receiver( :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index dc686304cbac..d55b37e22ade 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -343,7 +343,7 @@ def get_queue_receiver( :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. @@ -524,7 +524,7 @@ def get_subscription_receiver( :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 17ba6e1f3974..cdc69ee84346 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -119,7 +119,7 @@ class ServiceBusReceiver(AsyncIterator, BaseHandler, ReceiverMixin): :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting to a session. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. From 715901a00878d184313aa70e92561a99554a12cd Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 26 Jan 2024 15:19:43 -0800 Subject: [PATCH 45/50] pylint --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 0865435e8ce7..1f2066c392ab 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -107,7 +107,7 @@ class ServiceBusReceiver( specified Topic the client connects to. :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent messages to arrive. If no messages arrive, and no timeout is specified, this call will not return - until the connection is closed. The default value is None, meaning no timeout. On a sessionful + until the connection is closed. The default value is None, meaning no timeout. On a sessionful queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting to a session. If connection errors are occurring due to write timing out,the connection timeout value may need to be adjusted. See the `socket_timeout` optional parameter for more details. From 5e960815c4687dbf8b8b6bec2582a84db499ef54 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Mon, 29 Jan 2024 09:08:24 -0800 Subject: [PATCH 46/50] conn str doc update --- .../azure/servicebus/_servicebus_receiver.py | 9 +++++---- .../azure/servicebus/aio/_servicebus_receiver_async.py | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 1f2066c392ab..f0d7817c0d23 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -301,10 +301,11 @@ def _from_connection_string( The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent - messages to arrive, or the total time for the operation to complete. If no messages arrive, and no - timeout is specified, this call will not return until the connection is closed. The default value - is None, meaning no timeout. On a sesionful queue/topic when NEXT_AVAILABLE_SESSION is specified, - this will act as the timeout for connecting to a session. + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index cdc69ee84346..8592fb72ff01 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -298,8 +298,12 @@ def _from_connection_string( if the client fails to process the message. The default mode is PEEK_LOCK. :paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str] - :keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the - receiver will automatically stop receiving. The default value is None, meaning no timeout. + :keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent + messages to arrive. If no messages arrive, and no timeout is specified, this call will not return + until the connection is closed. The default value is None, meaning no timeout. On a sessionful + queue/topic when NEXT_AVAILABLE_SESSION is specified, this will act as the timeout for connecting + to a session. If connection errors are occurring due to write timing out,the connection timeout + value may need to be adjusted. See the `socket_timeout` optional parameter for more details. :keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`. :keyword transport_type: The type of transport protocol that will be used for communicating with the Service Bus service. Default is `TransportType.Amqp`. From 6d29fca8c1c10e4ab1e924fe37f17717943c107d Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 31 Jan 2024 10:15:24 -0800 Subject: [PATCH 47/50] remove ==True Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com> --- .../azure-servicebus/tests/async_tests/test_sessions_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py index 0dcbab69a3c6..4549d8230b73 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py @@ -1181,7 +1181,7 @@ async def test_async_session_non_session_send_to_session_queue_should_fail(self, @pytest.mark.parametrize("uamqp_transport", uamqp_transport_params, ids=uamqp_transport_ids) @ArgPasserAsync() async def test_async_next_available_session_timeout_value(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - if uamqp_transport==True: + if uamqp_transport: pytest.skip("This test is for pyamqp only") async with ServiceBusClient.from_connection_string( servicebus_namespace_connection_string, logging_enable=False, uamqp_transport=uamqp_transport) as sb_client: From 4631f4e9b5c9b563bba29c22f537181dd7c84890 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 31 Jan 2024 11:09:02 -0800 Subject: [PATCH 48/50] add >65 to test --- .../tests/async_tests/test_sessions_async.py | 13 ++++++++++++- .../azure-servicebus/tests/test_sessions.py | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py index 4549d8230b73..c26ea49b082c 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py @@ -1195,4 +1195,15 @@ async def test_async_next_available_session_timeout_value(self, uamqp_transport, with pytest.raises(OperationTimeoutError): async for msg in receiver: pass - assert time.time() - start_time2 < 65 # Default service timeout value is 65 seconds \ No newline at end of file + assert time.time() - start_time2 < 65 # Default service timeout value is 65 seconds + + receiver = sb_client.get_queue_receiver(servicebus_queue.name, session_id=NEXT_AVAILABLE_SESSION, max_wait_time=70) + start_time = time.time() + with pytest.raises(OperationTimeoutError): + await receiver.receive_messages(max_wait_time=5) + assert time.time() - start_time > 65 # Default service timeout value is 65 seconds + start_time2 = time.time() + with pytest.raises(OperationTimeoutError): + async for msg in receiver: + pass + assert time.time() - start_time2 > 65 # Default service timeout value is 65 seconds \ No newline at end of file diff --git a/sdk/servicebus/azure-servicebus/tests/test_sessions.py b/sdk/servicebus/azure-servicebus/tests/test_sessions.py index 45ed83fa251e..c9febcb66e87 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sessions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sessions.py @@ -1337,7 +1337,7 @@ def test_session_id_str_bytes(self, uamqp_transport, *, servicebus_namespace_con @pytest.mark.parametrize("uamqp_transport", uamqp_transport_params, ids=uamqp_transport_ids) @ArgPasser() def test_next_available_session_timeout_value(self, uamqp_transport, *, servicebus_namespace_connection_string=None, servicebus_queue=None, **kwargs): - if uamqp_transport==True: + if uamqp_transport: pytest.skip("This test is for pyamqp only") with ServiceBusClient.from_connection_string( servicebus_namespace_connection_string, logging_enable=False, uamqp_transport=uamqp_transport, retry_total=1) as sb_client: @@ -1354,3 +1354,16 @@ def test_next_available_session_timeout_value(self, uamqp_transport, *, serviceb pass assert time.time() - start_time2 < 65 # Default service operation timeout is 65 seconds + + receiver = sb_client.get_queue_receiver(servicebus_queue.name, session_id=NEXT_AVAILABLE_SESSION, max_wait_time=70) + + start_time = time.time() + with pytest.raises(OperationTimeoutError): + receiver.receive_messages(max_wait_time=5) + assert time.time() - start_time > 65 # Default service operation timeout is 65 seconds + start_time2 = time.time() + with pytest.raises(OperationTimeoutError): + for msg in receiver: + pass + + assert time.time() - start_time2 > 65 # Default service operation timeout is 65 seconds \ No newline at end of file From 7d994a3436cba89a3e2fa7c33710cea2c900610e Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 31 Jan 2024 11:27:28 -0800 Subject: [PATCH 49/50] add warning --- .../azure-servicebus/azure/servicebus/_servicebus_receiver.py | 4 ++++ .../azure/servicebus/aio/_servicebus_receiver_async.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index f0d7817c0d23..1dac81d37a79 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -694,6 +694,10 @@ def receive_messages( self._check_live() if max_wait_time is not None and max_wait_time <= 0: raise ValueError("The max_wait_time must be greater than 0.") + if max_wait_time is not None and self._session_id is not None: + warnings.warn(f"Setting max_wait_time on receive_messages when NEXT_AVAILABLE_SESSION" + " is specified will not impact the timeout for connecting to a session. Please use" + " max_wait_time on the constructor to set the timeout for connecting to a session.") if max_message_count is not None and max_message_count <= 0: raise ValueError("The max_message_count must be greater than 0") start_time = time.time_ns() diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 8592fb72ff01..8e976303d447 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -674,6 +674,10 @@ async def receive_messages( self._check_live() if max_wait_time is not None and max_wait_time <= 0: raise ValueError("The max_wait_time must be greater than 0.") + if max_wait_time is not None and self._session_id is not None: + warnings.warn(f"Setting max_wait_time on receive_messages when NEXT_AVAILABLE_SESSION" + " is specified will not impact the timeout for connecting to a session. Please use" + " max_wait_time on the constructor to set the timeout for connecting to a session.") if max_message_count is not None and max_message_count <= 0: raise ValueError("The max_message_count must be greater than 0") start_time = time.time_ns() From 77c8c41a41739e4d09238a9f22ed7801961fd68d Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Wed, 31 Jan 2024 15:15:37 -0800 Subject: [PATCH 50/50] move note to docstring --- .../azure/servicebus/_servicebus_receiver.py | 8 +++----- .../azure/servicebus/aio/_servicebus_receiver_async.py | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 1dac81d37a79..39d8661ad612 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -677,7 +677,9 @@ def receive_messages( :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. If specified, and no messages arrive within the - timeout period, an empty list will be returned. + timeout period, an empty list will be returned. NOTE: Setting max_wait_time on receive_messages + when NEXT_AVAILABLE_SESSION is specified will not impact the timeout for connecting to a session. + Please use max_wait_time on the constructor to set the timeout for connecting to a session. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: List[~azure.servicebus.ServiceBusReceivedMessage] @@ -694,10 +696,6 @@ def receive_messages( self._check_live() if max_wait_time is not None and max_wait_time <= 0: raise ValueError("The max_wait_time must be greater than 0.") - if max_wait_time is not None and self._session_id is not None: - warnings.warn(f"Setting max_wait_time on receive_messages when NEXT_AVAILABLE_SESSION" - " is specified will not impact the timeout for connecting to a session. Please use" - " max_wait_time on the constructor to set the timeout for connecting to a session.") if max_message_count is not None and max_message_count <= 0: raise ValueError("The max_message_count must be greater than 0") start_time = time.time_ns() diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 8e976303d447..74b8690bc9c1 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -657,7 +657,9 @@ async def receive_messages( :param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. If specified, and no messages arrive within the - timeout period, an empty list will be returned. + timeout period, an empty list will be returned. NOTE: Setting max_wait_time on receive_messages + when NEXT_AVAILABLE_SESSION is specified will not impact the timeout for connecting to a session. + Please use max_wait_time on the constructor to set the timeout for connecting to a session. :return: A list of messages received. If no messages are available, this will be an empty list. :rtype: list[~azure.servicebus.aio.ServiceBusReceivedMessage] @@ -674,10 +676,6 @@ async def receive_messages( self._check_live() if max_wait_time is not None and max_wait_time <= 0: raise ValueError("The max_wait_time must be greater than 0.") - if max_wait_time is not None and self._session_id is not None: - warnings.warn(f"Setting max_wait_time on receive_messages when NEXT_AVAILABLE_SESSION" - " is specified will not impact the timeout for connecting to a session. Please use" - " max_wait_time on the constructor to set the timeout for connecting to a session.") if max_message_count is not None and max_message_count <= 0: raise ValueError("The max_message_count must be greater than 0") start_time = time.time_ns()