Skip to content

Commit ac02a3c

Browse files
authored
[SB] Update max_wait_time docstrings (Azure#31513)
* update docstring * update receive_messages() * deprecation docstring * update doc * update statement * pylint * update wording * line too long * update deprecation statement * add warnings.warn * update deprecation * remove deprecated max_wait_time * add back msg count * update max_wait_time samples
1 parent e5f53f6 commit ac02a3c

22 files changed

+153
-121
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,12 @@ def get_queue_receiver(
356356
will be immediately removed from the queue, and cannot be subsequently rejected or re-received if
357357
the client fails to process the message. The default receive_mode is PEEK_LOCK.
358358
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
359-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
360-
receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection
361-
errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See
362-
the `socket_timeout` optional parameter for more details.
359+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
360+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
361+
and no timeout is specified, this call will not return until the connection is closed.
362+
The default value is None, meaning no timeout. If connection errors are occurring due to write timing out,
363+
the connection timeout value may need to be adjusted. See the `socket_timeout`
364+
optional parameter for more details.
363365
:keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer
364366
can be provided such that messages are automatically registered on receipt. If the receiver is a session
365367
receiver, it will apply to the session instead.
@@ -538,10 +540,12 @@ def get_subscription_receiver(
538540
will be immediately removed from the subscription, and cannot be subsequently rejected or re-received if
539541
the client fails to process the message. The default receive_mode is PEEK_LOCK.
540542
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
541-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
542-
receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection
543-
errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See
544-
the `socket_timeout` optional parameter for more details.
543+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
544+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
545+
and no timeout is specified, this call will not return until the connection is closed.
546+
The default value is None, meaning no timeout. If connection errors are occurring due to write timing out,
547+
the connection timeout value may need to be adjusted. See the `socket_timeout`
548+
optional parameter for more details.
545549
:keyword Optional[~azure.servicebus.AutoLockRenewer] auto_lock_renewer: An ~azure.servicebus.AutoLockRenewer
546550
can be provided such that messages are automatically registered on receipt. If the receiver is a session
547551
receiver, it will apply to the session instead.

sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ class ServiceBusReceiver(
105105
the client connects to.
106106
:keyword str subscription_name: The path of specific Service Bus Subscription under the
107107
specified Topic the client connects to.
108-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
109-
receiver will automatically stop receiving. The default value is None, meaning no timeout.
108+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
109+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
110+
and no timeout is specified, this call will not return until the connection is closed.
111+
The default value is None, meaning no timeout.
110112
:keyword receive_mode: The mode with which messages will be retrieved from the entity. The two options
111113
are PEEK_LOCK and RECEIVE_AND_DELETE. Messages received with PEEK_LOCK must be settled within a given
112114
lock period before they will be removed from the queue. Messages received with RECEIVE_AND_DELETE
@@ -286,8 +288,10 @@ def _from_connection_string(
286288
if the client fails to process the message.
287289
The default mode is PEEK_LOCK.
288290
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
289-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
290-
receiver will automatically stop receiving. The default value is None, meaning no timeout.
291+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
292+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
293+
and no timeout is specified, this call will not return until the connection is closed.
294+
The default value is None, meaning no timeout.
291295
:keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`.
292296
:keyword transport_type: The type of transport protocol that will be used for communicating with
293297
the Service Bus service. Default is `TransportType.Amqp`.
@@ -656,10 +660,10 @@ def receive_messages(
656660
:param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number
657661
returned will depend on prefetch_count and incoming stream rate.
658662
Setting to None will fully depend on the prefetch config. The default value is 1.
659-
:param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive.
660-
If no messages arrive, and no timeout is specified, this call will not return
661-
until the connection is closed. If specified, an no messages arrive within the
662-
timeout period, an empty list will be returned.
663+
:param Optional[float] max_wait_time: DEPRECATED. It is not advised to use this parameter when
664+
calling this method. If you'd like to specify max_wait_time, please pass it in during client
665+
construction. If specified, this parameter will interact with the absolute operation timeout
666+
and impact the amount of time alloted to retry the receive operation.
663667
:return: A list of messages received. If no messages are available, this will be an empty list.
664668
:rtype: List[~azure.servicebus.ServiceBusReceivedMessage]
665669
@@ -674,6 +678,8 @@ def receive_messages(
674678
675679
"""
676680
self._check_live()
681+
if max_wait_time:
682+
warnings.warn("max_wait_time is deprecated. Please set it in client constructor.", DeprecationWarning)
677683
if max_wait_time is not None and max_wait_time <= 0:
678684
raise ValueError("The max_wait_time must be greater than 0.")
679685
if max_message_count is not None and max_message_count <= 0:

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,12 @@ def get_queue_receiver(
341341
will be immediately removed from the queue, and cannot be subsequently rejected or re-received if
342342
the client fails to process the message. The default mode is PEEK_LOCK.
343343
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
344-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
345-
receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection
346-
errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See
347-
the `socket_timeout` optional parameter for more details.
344+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
345+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
346+
and no timeout is specified, this call will not return until the connection is closed.
347+
The default value is None, meaning no timeout. If connection errors are occurring due to write timing out,
348+
the connection timeout value may need to be adjusted. See the `socket_timeout`
349+
optional parameter for more details.
348350
:keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An
349351
~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on
350352
receipt. If the receiver is a session receiver, it will apply to the session instead.
@@ -520,10 +522,12 @@ def get_subscription_receiver(
520522
will be immediately removed from the subscription, and cannot be subsequently rejected or re-received if
521523
the client fails to process the message. The default mode is PEEK_LOCK.
522524
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
523-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
524-
receiver will automatically stop receiving. The default value is None, meaning no timeout. If connection
525-
errors are occurring due to write timing out, the connection timeout value may need to be adjusted. See
526-
the `socket_timeout` optional parameter for more details.
525+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
526+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
527+
and no timeout is specified, this call will not return until the connection is closed.
528+
The default value is None, meaning no timeout. If connection errors are occurring due to write timing out,
529+
the connection timeout value may need to be adjusted. See the `socket_timeout`
530+
optional parameter for more details.
527531
:keyword Optional[~azure.servicebus.aio.AutoLockRenewer] auto_lock_renewer: An
528532
~azure.servicebus.aio.AutoLockRenewer can be provided such that messages are automatically registered on
529533
receipt. If the receiver is a session receiver, it will apply to the session instead.

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ class ServiceBusReceiver(collections.abc.AsyncIterator, BaseHandler, ReceiverMix
109109
if the client fails to process the message.
110110
The default mode is PEEK_LOCK.
111111
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
112-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the receiver
113-
will automatically stop receiving. The default value is None, meaning no timeout.
112+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
113+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
114+
and no timeout is specified, this call will not return until the connection is closed.
115+
The default value is None, meaning no timeout.
114116
:keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`.
115117
:keyword transport_type: The type of transport protocol that will be used for communicating with
116118
the Service Bus service. Default is `TransportType.Amqp`.
@@ -277,8 +279,10 @@ def _from_connection_string(
277279
if the client fails to process the message.
278280
The default mode is PEEK_LOCK.
279281
:paramtype receive_mode: Union[~azure.servicebus.ServiceBusReceiveMode, str]
280-
:keyword Optional[float] max_wait_time: The timeout in seconds between received messages after which the
281-
receiver will automatically stop receiving. The default value is None, meaning no timeout.
282+
:keyword Optional[float] max_wait_time: The timeout in seconds to wait for the first and subsequent
283+
messages to arrive after which the receiver will automatically stop receiving. If no messages arrive,
284+
and no timeout is specified, this call will not return until the connection is closed.
285+
The default value is None, meaning no timeout.
282286
:keyword bool logging_enable: Whether to output network trace logs to the logger. Default is `False`.
283287
:keyword transport_type: The type of transport protocol that will be used for communicating with
284288
the Service Bus service. Default is `TransportType.Amqp`.
@@ -629,10 +633,10 @@ async def receive_messages(
629633
:param Optional[int] max_message_count: Maximum number of messages in the batch. Actual number
630634
returned will depend on prefetch_count size and incoming stream rate.
631635
Setting to None will fully depend on the prefetch config. The default value is 1.
632-
:param Optional[float] max_wait_time: Maximum time to wait in seconds for the first message to arrive.
633-
If no messages arrive, and no timeout is specified, this call will not return
634-
until the connection is closed. If specified, and no messages arrive within the
635-
timeout period, an empty list will be returned.
636+
:param Optional[float] max_wait_time: DEPRECATED. It is not advised to use this parameter when
637+
calling this method. If you'd like to specify max_wait_time, please pass it in during client
638+
construction. If specified, this parameter will interact with the absolute operation timeout
639+
and impact the amount of time alloted to retry the receive operation.
636640
:return: A list of messages received. If no messages are available, this will be an empty list.
637641
:rtype: list[~azure.servicebus.aio.ServiceBusReceivedMessage]
638642
@@ -647,6 +651,8 @@ async def receive_messages(
647651
648652
"""
649653
self._check_live()
654+
if max_wait_time:
655+
warnings.warn("max_wait_time is deprecated. Please set it in client constructor.", DeprecationWarning)
650656
if max_wait_time is not None and max_wait_time <= 0:
651657
raise ValueError("The max_wait_time must be greater than 0.")
652658
if max_message_count is not None and max_message_count <= 0:

sdk/servicebus/azure-servicebus/samples/async_samples/auto_lock_renew_async.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ async def renew_lock_on_message_received_from_non_sessionful_entity():
3939
# Can also be called via "with AutoLockRenewer() as renewer" to automate shutdown.
4040
renewer = AutoLockRenewer()
4141

42-
async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, prefetch_count=10) as receiver:
43-
received_msgs = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
42+
async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, prefetch_count=10, max_wait_time=5) as receiver:
43+
received_msgs = await receiver.receive_messages(max_message_count=10)
4444

4545
for msg in received_msgs:
4646
# automatically renew the lock on each message for 100 seconds
@@ -71,13 +71,14 @@ async def renew_lock_on_session_of_the_sessionful_entity():
7171
async with servicebus_client.get_queue_receiver(
7272
queue_name=SESSION_QUEUE_NAME,
7373
session_id='SESSION',
74-
prefetch_count=10
74+
prefetch_count=10,
75+
max_wait_time=5
7576
) as receiver:
7677
# automatically renew the lock on the session for 100 seconds
7778
renewer.register(receiver, receiver.session, max_lock_renewal_duration=100)
7879
print('Register session into AutoLockRenewer.')
7980

80-
received_msgs = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
81+
received_msgs = await receiver.receive_messages(max_message_count=10)
8182
await asyncio.sleep(100) # message handling for long period (E.g. application logic)
8283

8384
for msg in received_msgs:
@@ -96,7 +97,7 @@ async def renew_lock_with_lock_renewal_failure_callback():
9697
# For this sample we're going to set the renewal recurrence of the autolockrenewer to greater than the
9798
# service side message lock duration, to demonstrate failure. Normally, this should not be adjusted.
9899
renewer._sleep_time = 40
99-
async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, prefetch_count=10) as receiver:
100+
async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, prefetch_count=10, max_wait_time=5) as receiver:
100101

101102
async def on_lock_renew_failure_callback(renewable, error):
102103
# If auto-lock-renewal fails, this function will be called.
@@ -106,7 +107,7 @@ async def on_lock_renew_failure_callback(renewable, error):
106107
# handle any processing on the message or session that was in progress.
107108
print("Intentionally failed to renew lock on {} due to {}".format(renewable, error))
108109

109-
received_msgs = await receiver.receive_messages(max_message_count=1, max_wait_time=5)
110+
received_msgs = await receiver.receive_messages(max_message_count=1)
110111

111112
for msg in received_msgs:
112113
# automatically renew the lock on each message for 120 seconds

0 commit comments

Comments
 (0)