AutoLockRenewer Class

Auto lock renew.

An asynchronous AutoLockRenewer handler for renewing the lock tokens of messages and/or sessions in the background.

Inheritance
builtins.object
AutoLockRenewer

Constructor

AutoLockRenewer(max_lock_renewal_duration: float = 300, on_lock_renew_failure: Callable[[ServiceBusSession | ServiceBusReceivedMessage, Exception | None], Awaitable[None]] | None = None, loop: AbstractEventLoop | None = None)

Parameters

Name Description
max_lock_renewal_duration

A time in seconds that locks registered to this renewer should be maintained for. Default value is 300 (5 minutes).

Default value: 300
on_lock_renew_failure
Optional[<xref:LockRenewFailureCallback>]

A callback may be specified to be called when the lock is lost on the renewable that is being registered. Default value is None (no callback).

Default value: None
loop
Default value: None

Examples

Automatically renew a message lock


   from azure.servicebus.aio import AutoLockRenewer

   lock_renewal = AutoLockRenewer()
   async with servicebus_receiver:
       async for message in servicebus_receiver:
           lock_renewal.register(servicebus_receiver, message, max_lock_renewal_duration=60)
           await process_message(message)
           await servicebus_receiver.complete_message(message)

Automatically renew a session lock


       from azure.servicebus.aio import AutoLockRenewer

       lock_renewal = AutoLockRenewer()
       async with servicebus_client.get_queue_receiver(queue_name=queue_name, session_id=session_id) as receiver:
           session = receiver.session
           # Auto renew session lock for 2 minutes
           lock_renewal.register(receiver, session, max_lock_renewal_duration=120)
           async for message in receiver:
               await process_message(message)
               await receiver.complete_message(message)

Methods

close

Cease autorenewal by cancelling any remaining open lock renewal futures.

register

Register a renewable entity for automatic lock renewal.

close

Cease autorenewal by cancelling any remaining open lock renewal futures.

async close() -> None

register

Register a renewable entity for automatic lock renewal.

register(receiver: ServiceBusReceiver, renewable: ServiceBusReceivedMessage | ServiceBusSession, max_lock_renewal_duration: float | None = None, on_lock_renew_failure: Callable[[ServiceBusSession | ServiceBusReceivedMessage, Exception | None], Awaitable[None]] | None = None) -> None

Parameters

Name Description
receiver
Required

The ServiceBusReceiver instance that is associated with the message or the session to be auto-lock-renewed.

renewable
Required
Union[<xref:azure.servicebus.aio.ServiceBusReceivedMessage>,ServiceBusSession]

A locked entity that needs to be renewed.

max_lock_renewal_duration

A time in seconds that the lock should be maintained for. Default value is None. If specified, this value will override the default value specified at the constructor.

Default value: None
on_lock_renew_failure
Optional[<xref:AsyncLockRenewFailureCallback>]

An async callback may be specified to be called when the lock is lost on the renewable being registered. Default value is None (no callback). :rtype: None

Default value: None