azure.servicebus.common package

Submodules

azure.servicebus.common.constants module

class azure.servicebus.common.constants.ReceiveSettleMode[source]

An enumeration.

PeekLock = <ReceiverSettleMode.PeekLock: 1>
ReceiveAndDelete = <ReceiverSettleMode.ReceiveAndDelete: 0>
class azure.servicebus.common.constants.SessionFilter[source]

An enumeration.

NextAvailable = 0

azure.servicebus.common.errors module

exception azure.servicebus.common.errors.AutoLockRenewFailed(message, inner_exception=None)[source]

An attempt to renew a lock on a message or session in the background has failed.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.AutoLockRenewTimeout(message, inner_exception=None)[source]

The time allocated to renew the message or session lock has elapsed.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.InvalidHandlerState(message, inner_exception=None)[source]

An attempt to run a handler operation that the handler is not in the right state to perform.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.MessageAlreadySettled(action)[source]

Failed to settle the message.

An attempt was made to complete an operation on a message that has already been settled (completed, abandoned, dead-lettered or deferred). This error will also be raised if an attempt is made to settle a message received via ReceiveAndDelete mode.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.MessageLockExpired(message=None, inner_exception=None)[source]

The lock on the message has expired and it has been released back to the queue.

It will need to be received again in order to settle it.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.MessageSendFailed(inner_exception)[source]

A message failed to send to the Service Bus entity.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.MessageSettleFailed(action, inner_exception)[source]

Attempt to settle a message failed.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.NoActiveSession(message, inner_exception=None)[source]

No active Sessions are available to receive from.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.ServiceBusAuthorizationError(message, inner_exception=None)[source]

An error occured when authorizing the connection.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.ServiceBusConnectionError(message, inner_exception=None)[source]

An error occured in the connection.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.ServiceBusError(message, inner_exception=None)[source]

An error occured.

This is the parent of all Service Bus errors and can be used for default error handling.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.ServiceBusResourceNotFound(message, inner_exception=None)[source]

The Service Bus entity could not be reached.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.servicebus.common.errors.SessionLockExpired(message=None, inner_exception=None)[source]

The lock on the session has expired.

All unsettled messages that have been received can no longer be settled.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args

azure.servicebus.common.message module

class azure.servicebus.common.message.BatchMessage(body, encoding='UTF-8', **kwargs)[source]

A batch of messages combined into a single message body.

The body of the messages in the batch should be supplied by an iterable, such as a generator. If the contents of the iterable exceeds the maximum size of a single message (256 kB), the data will be broken up across multiple messages.

Parameters
  • body (Iterable) – The data to send in each message in the batch. The maximum size per message is 256 kB. If data is supplied in excess of this limit, multiple messages will be sent.

  • encoding (str) – The encoding for string data. Default is UTF-8.

abandon()

Abandon the message.

This message will be returned to the queue to be reprocessed.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

complete()

Complete the message.

This removes the message from the queue.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

dead_letter(description=None, reason=None)

Move the message to the Dead Letter queue.

The Dead Letter queue is a sub-queue that can be used to store messages that failed to process correctly, or otherwise require further inspection or processing. The queue can also be configured to send expired messages to the Dead Letter queue. To receive dead-lettered messages, use QueueClient.get_deadletter_receiver() or SubscriptionClient.get_deadletter_receiver().

Parameters
  • description (str) – The error description for dead-lettering the message.

  • reason (str) – The reason for dead-lettering the message. If reason is not set while description is set, then reason would be set the same as description.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

defer()

Defer the message.

This message will remain in the queue but must be received specifically by its sequence number in order to be processed.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

renew_lock()

Renew the message lock.

This will maintain the lock on the message to ensure it is not returned to the queue to be reprocessed. In order to complete (or otherwise settle) the message, the lock must be maintained. Messages received via ReceiveAndDelete mode are not locked, and therefore cannot be renewed. This operation can also be performed as a threaded background task by registering the message with an azure.servicebus.AutoLockRenew instance. This operation is only available for non-sessionful messages.

Raises

TypeError if the message is sessionful.

Raises

~azure.servicebus.common.errors.MessageLockExpired is message lock has already expired.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled is message has already been settled.

schedule(schedule_time)

Add a specific enqueue time to the message.

Parameters

schedule_time (datetime) – The scheduled time to enqueue the message.

property annotations

The annotations of the message.

Return type

dict

property body

The body of the Message.

Return type

bytes or generator[bytes]

property enqueue_sequence_number
property enqueued_time
property expired
property lock_token
property locked_until
property partition_id
property partition_key
property scheduled_enqueue_time
property sequence_number
property session_id
property settled

Whether the message has been settled.

This will aways be True for a message received using ReceiveAndDelete mode, otherwise it will be False until the message is completed or otherwise settled.

Return type

bool

property time_to_live
property user_properties

User defined properties on the message.

Return type

dict

property via_partition_key
class azure.servicebus.common.message.DeferredMessage(message, mode)[source]

A message that has been deferred.

A deferred message can be completed, abandoned, or dead-lettered, however it cannot be deferred again.

abandon()[source]

Abandon the message.

This message will be returned to the queue to be reprocessed.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

complete()[source]

Complete the message.

This removes the message from the queue.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

dead_letter(description=None, reason=None)[source]

Move the message to the Dead Letter queue.

The Dead Letter queue is a sub-queue that can be used to store messages that failed to process correctly, or otherwise require further inspection or processing. The queue can also be configured to send expired messages to the Dead Letter queue. To receive dead-lettered messages, use QueueClient.get_deadletter_receiver() or SubscriptionClient.get_deadletter_receiver().

Parameters
  • description (str) – The error description for dead-lettering the message.

  • reason (str) – The reason for dead-lettering the message. If reason is not set while description is set, then reason would be set the same as description.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

defer()[source]

A DeferredMessage cannot be deferred. Raises ValueError.

renew_lock()

Renew the message lock.

This will maintain the lock on the message to ensure it is not returned to the queue to be reprocessed. In order to complete (or otherwise settle) the message, the lock must be maintained. Messages received via ReceiveAndDelete mode are not locked, and therefore cannot be renewed. This operation can also be performed as a threaded background task by registering the message with an azure.servicebus.AutoLockRenew instance. This operation is only available for non-sessionful messages.

Raises

TypeError if the message is sessionful.

Raises

~azure.servicebus.common.errors.MessageLockExpired is message lock has already expired.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled is message has already been settled.

schedule(schedule_time)

Add a specific enqueue time to the message.

Parameters

schedule_time (datetime) – The scheduled time to enqueue the message.

property annotations

The annotations of the message.

Return type

dict

property body

The body of the Message.

Return type

bytes or generator[bytes]

property enqueue_sequence_number
property enqueued_time
property expired
property lock_token
property locked_until
property partition_id
property partition_key
property scheduled_enqueue_time
property sequence_number
property session_id
property settled

Whether the message has been settled.

This will aways be True for a message received using ReceiveAndDelete mode, otherwise it will be False until the message is completed or otherwise settled.

Return type

bool

property time_to_live
property user_properties

User defined properties on the message.

Return type

dict

property via_partition_key
class azure.servicebus.common.message.Message(body, encoding='UTF-8', **kwargs)[source]

A Service Bus Message.

Parameters
  • body (str or bytes) – The data to send in a single message. The maximum size per message is 256 kB.

  • encoding (str) – The encoding for string data. Default is UTF-8.

Example: .. literalinclude:: ../samples/sync_samples/test_examples.py :start-after: [START send_complex_message] :end-before: [END send_complex_message] :language: python :dedent: 4 :caption: Sending a message with additional properties

Checking the properties on a received message
with queue_client.get_receiver(idle_timeout=3) as receiver:
    for message in receiver:
        print("Receiving: {}".format(message))
        print("Time to live: {}".format(message.time_to_live))
        print("Sequence number: {}".format(message.sequence_number))
        print("Enqueue Sequence numger: {}".format(message.enqueue_sequence_number))
        print("Partition ID: {}".format(message.partition_id))
        print("Partition Key: {}".format(message.partition_key))
        print("User Properties: {}".format(message.user_properties))
        print("Annotations: {}".format(message.annotations))
        print("Delivery count: {}".format(message.header.delivery_count))
        print("Message ID: {}".format(message.properties.message_id))
        print("Locked until: {}".format(message.locked_until))
        print("Lock Token: {}".format(message.lock_token))
        print("Enqueued time: {}".format(message.enqueued_time))
abandon()[source]

Abandon the message.

This message will be returned to the queue to be reprocessed.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

complete()[source]

Complete the message.

This removes the message from the queue.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

dead_letter(description=None, reason=None)[source]

Move the message to the Dead Letter queue.

The Dead Letter queue is a sub-queue that can be used to store messages that failed to process correctly, or otherwise require further inspection or processing. The queue can also be configured to send expired messages to the Dead Letter queue. To receive dead-lettered messages, use QueueClient.get_deadletter_receiver() or SubscriptionClient.get_deadletter_receiver().

Parameters
  • description (str) – The error description for dead-lettering the message.

  • reason (str) – The reason for dead-lettering the message. If reason is not set while description is set, then reason would be set the same as description.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

defer()[source]

Defer the message.

This message will remain in the queue but must be received specifically by its sequence number in order to be processed.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled if the message has been settled.

Raises

~azure.servicebus.common.errors.MessageLockExpired if message lock has already expired.

Raises

~azure.servicebus.common.errors.SessionLockExpired if session lock has already expired.

Raises

~azure.servicebus.common.errors.MessageSettleFailed if message settle operation fails.

renew_lock()[source]

Renew the message lock.

This will maintain the lock on the message to ensure it is not returned to the queue to be reprocessed. In order to complete (or otherwise settle) the message, the lock must be maintained. Messages received via ReceiveAndDelete mode are not locked, and therefore cannot be renewed. This operation can also be performed as a threaded background task by registering the message with an azure.servicebus.AutoLockRenew instance. This operation is only available for non-sessionful messages.

Raises

TypeError if the message is sessionful.

Raises

~azure.servicebus.common.errors.MessageLockExpired is message lock has already expired.

Raises

~azure.servicebus.common.errors.MessageAlreadySettled is message has already been settled.

schedule(schedule_time)[source]

Add a specific enqueue time to the message.

Parameters

schedule_time (datetime) – The scheduled time to enqueue the message.

property annotations

The annotations of the message.

Return type

dict

property body

The body of the Message.

Return type

bytes or generator[bytes]

property enqueue_sequence_number
property enqueued_time
property expired
property lock_token
property locked_until
property partition_id
property partition_key
property scheduled_enqueue_time
property sequence_number
property session_id
property settled

Whether the message has been settled.

This will aways be True for a message received using ReceiveAndDelete mode, otherwise it will be False until the message is completed or otherwise settled.

Return type

bool

property time_to_live
property user_properties

User defined properties on the message.

Return type

dict

property via_partition_key
class azure.servicebus.common.message.PeekMessage(message)[source]

A preview message.

This message is still on the queue, and unlocked. A peeked message cannot be completed, abandoned, dead-lettered or deferred. It has no lock token or expiry.

abandon()[source]

A PeekMessage cannot be abandoned. Raises TypeError.

complete()[source]

A PeekMessage cannot be completed Raises TypeError.

dead_letter(description=None, reason=None)[source]

A PeekMessage cannot be dead-lettered. Raises TypeError.

defer()[source]

A PeekMessage cannot be deferred. Raises TypeError.

renew_lock()[source]

A PeekMessage cannot be renewed. Raises TypeError.

schedule(schedule_time)

Add a specific enqueue time to the message.

Parameters

schedule_time (datetime) – The scheduled time to enqueue the message.

property annotations

The annotations of the message.

Return type

dict

property body

The body of the Message.

Return type

bytes or generator[bytes]

property enqueue_sequence_number
property enqueued_time
property expired
property lock_token
property locked_until
property partition_id
property partition_key
property scheduled_enqueue_time
property sequence_number
property session_id
property settled

Whether the message has been settled.

This will aways be True for a message received using ReceiveAndDelete mode, otherwise it will be False until the message is completed or otherwise settled.

Return type

bool

property time_to_live
property user_properties

User defined properties on the message.

Return type

dict

property via_partition_key

azure.servicebus.common.mgmt_handlers module

azure.servicebus.common.mgmt_handlers.default(status_code, message, description)[source]
azure.servicebus.common.mgmt_handlers.deferred_message_op(status_code, message, description, mode=1, message_type=<class 'azure.servicebus.common.message.DeferredMessage'>)[source]
azure.servicebus.common.mgmt_handlers.list_sessions_op(status_code, message, description)[source]
azure.servicebus.common.mgmt_handlers.lock_renew_op(status_code, message, description)[source]
azure.servicebus.common.mgmt_handlers.peek_op(status_code, message, description)[source]
azure.servicebus.common.mgmt_handlers.schedule_op(status_code, message, description)[source]

azure.servicebus.common.mixins module

class azure.servicebus.common.mixins.BaseClient(address, name, shared_access_key_name=None, shared_access_key_value=None, debug=False, **kwargs)[source]

Construct a new Client to interact with the named Service Bus entity.

Parameters
  • address (str) – The full URI of the Service Bus namespace. This can optionally include URL-encoded access name and key.

  • name (str) – The name of the entity to which the Client will connect.

  • shared_access_key_name (str) – The name of the shared access policy. This must be supplied if not encoded into the address.

  • shared_access_key_value (str) – The shared access key. This must be supplied if not encoded into the address.

  • debug (bool) – Whether to output network trace logs to the logger. Default is False.

classmethod from_connection_string(conn_str, name=None, **kwargs)[source]

Create a Client from a Service Bus connection string.

Parameters
  • conn_str (str) – The connection string.

  • name – The name of the entity, if the ‘EntityName’ property is not included in the connection string.

classmethod from_entity(address, entity, **kwargs)[source]
get_properties()[source]

Perform an operation to update the properties of the entity.

Returns

The properties of the entity as a dictionary.

Return type

dict[str, Any]

Raises

~azure.servicebus.common.errors.ServiceBusResourceNotFound if the entity does not exist.

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the endpoint cannot be reached.

Raises

~azure.common.AzureHTTPError if the credentials are invalid.

class azure.servicebus.common.mixins.SenderMixin[source]
queue_message(message)[source]

Queue a message to be sent later.

This operation should be followed up with send_pending_messages.

Parameters

message (Message) – The message to be sent.

class azure.servicebus.common.mixins.ServiceBusMixin[source]
create_queue(queue_name, lock_duration=30, max_size_in_megabytes=None, requires_duplicate_detection=False, requires_session=False, default_message_time_to_live=None, dead_lettering_on_message_expiration=False, duplicate_detection_history_time_window=None, max_delivery_count=None, enable_batched_operations=None)[source]

Create a queue entity.

Parameters
  • queue_name (str) – The name of the new queue.

  • lock_duration (int) – The lock durection in seconds for each message in the queue.

  • max_size_in_megabytes (int) – The max size to allow the queue to grow to.

  • requires_duplicate_detection (bool) – Whether the queue will require every message with a specified time frame to have a unique ID. Non-unique messages will be discarded. Default value is False.

  • requires_session (bool) – Whether the queue will be sessionful, and therefore require all message to have a Session ID and be received by a sessionful receiver. Default value is False.

  • default_message_time_to_live (timedelta) – The length of time a message will remain in the queue before it is either discarded or moved to the dead letter queue.

  • dead_lettering_on_message_expiration (bool) – Whether to move expired messages to the dead letter queue. Default value is False.

  • duplicate_detection_history_time_window (timedelta) – The period within which all incoming messages must have a unique message ID.

  • max_delivery_count (int) – The maximum number of times a message will attempt to be delivered before it is moved to the dead letter queue.

  • enable_batched_operations

Type

enable_batched_operations: bool

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namespace is not found.

Raises

~azure.common.AzureConflictHttpError if a queue of the same name already exists.

create_subscription(topic_name, subscription_name, lock_duration=30, requires_session=None, default_message_time_to_live=None, dead_lettering_on_message_expiration=None, dead_lettering_on_filter_evaluation_exceptions=None, enable_batched_operations=None, max_delivery_count=None)[source]

Create a subscription entity.

Parameters
  • topic_name – The name of the topic under which to create the subscription.

  • subscription_name (str) – The name of the new subscription.

  • lock_duration (int) – The lock durection in seconds for each message in the subscription.

  • requires_session (bool) – Whether the subscription will be sessionful, and therefore require all message to have a Session ID and be received by a sessionful receiver. Default value is False.

  • default_message_time_to_live (timedelta) – The length of time a message will remain in the subscription before it is either discarded or moved to the dead letter queue.

  • dead_lettering_on_message_expiration (bool) – Whether to move expired messages to the dead letter queue. Default value is False.

  • dead_lettering_on_filter_evaluation_exceptions (bool) – Whether to move messages that error on filtering into the dead letter queue. Default is False, and the messages will be discarded.

  • max_delivery_count (int) – The maximum number of times a message will attempt to be delivered before it is moved to the dead letter queue.

  • enable_batched_operations

Type

enable_batched_operations: bool

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namespace is not found.

Raises

~azure.common.AzureConflictHttpError if a queue of the same name already exists.

create_topic(topic_name, default_message_time_to_live=None, max_size_in_megabytes=None, requires_duplicate_detection=None, duplicate_detection_history_time_window=None, enable_batched_operations=None)[source]

Create a topic entity.

Parameters
  • topic_name (str) – The name of the new topic.

  • max_size_in_megabytes (int) – The max size to allow the topic to grow to.

  • requires_duplicate_detection (bool) – Whether the topic will require every message with a specified time frame to have a unique ID. Non-unique messages will be discarded. Default value is False.

  • default_message_time_to_live (timedelta) – The length of time a message will remain in the topic before it is either discarded or moved to the dead letter queue.

  • duplicate_detection_history_time_window (timedelta) – The period within which all incoming messages must have a unique message ID.

  • enable_batched_operations

Type

enable_batched_operations: bool

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namespace is not found.

Raises

~azure.common.AzureConflictHttpError if a topic of the same name already exists.

delete_queue(queue_name, fail_not_exist=False)[source]

Delete a queue entity.

Parameters
  • queue_name (str) – The name of the queue to delete.

  • fail_not_exist (bool) – Whether to raise an exception if the named queue is not found. If set to True, a ServiceBusResourceNotFound will be raised. Default value is False.

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namesapce is not found.

Raises

~azure.servicebus.common.errors.ServiceBusResourceNotFound if the queue is not found and fail_not_exist is set to True.

delete_subscription(topic_name, subscription_name, fail_not_exist=False)[source]

Delete a subscription entity.

Parameters
  • topic_name (str) – The name of the topic where the subscription is.

  • subscription_name (str) – The name of the subscription to delete.

  • fail_not_exist (bool) – Whether to raise an exception if the named subscription or topic is not found. If set to True, a ServiceBusResourceNotFound will be raised. Default value is False.

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namesapce is not found.

Raises

~azure.servicebus.common.errors.ServiceBusResourceNotFound if the entity is not found and fail_not_exist is set to True.

delete_topic(topic_name, fail_not_exist=False)[source]

Delete a topic entity.

Parameters
  • topic_name (str) – The name of the topic to delete.

  • fail_not_exist (bool) – Whether to raise an exception if the named topic is not found. If set to True, a ServiceBusResourceNotFound will be raised. Default value is False.

Raises

~azure.servicebus.common.errors.ServiceBusConnectionError if the namesapce is not found.

Raises

~azure.servicebus.common.errors.ServiceBusResourceNotFound if the topic is not found and fail_not_exist is set to True.

class azure.servicebus.common.mixins.SessionMixin[source]
property expired

Whether the receivers lock on a particular session has expired.

Return type

bool

azure.servicebus.common.utils module

class azure.servicebus.common.utils.AutoLockRenew(executor=None, max_workers=None)[source]

Auto renew locks for messages and sessions using a background thread pool.

Parameters
  • executor (ThreadPoolExecutor) – A user-specified thread pool. This cannot be combined with setting max_workers.

  • max_workers (int) – Specifiy the maximum workers in the thread pool. If not specified the number used will be derived from the core count of the environment. This cannot be combined with executor.

Example: .. literalinclude:: ../samples/sync_samples/test_examples.py :start-after: [START auto_lock_renew_message] :end-before: [END auto_lock_renew_message] :language: python :dedent: 4 :caption: Automatically renew a message lock

Automatically renew a session lock
from azure.servicebus import AutoLockRenew

lock_renewal = AutoLockRenew(max_workers=4)
with session_client.get_receiver(session="MySessionID", idle_timeout=3) as session:
    # Auto renew session lock for 2 minutes
    lock_renewal.register(session, timeout=120)

    for message in session:
        process_message(message)
        message.complete()
register(renewable, timeout=300)[source]

Register a renewable entity for automatic lock renewal.

Parameters
  • renewable (Message or SessionReceiver) – A locked entity that needs to be renewed.

  • timeout (int) – A time in seconds that the lock should be maintained for. Default value is 300 (5 minutes).

shutdown(wait=True)[source]

Shutdown the thread pool to clean up any remaining lock renewal threads.

Parameters

wait (bool) – Whether to block until thread pool has shutdown. Default is True.

azure.servicebus.common.utils.build_uri(address, entity)[source]
azure.servicebus.common.utils.create_properties()[source]
azure.servicebus.common.utils.get_running_loop()[source]
azure.servicebus.common.utils.parse_conn_str(conn_str)[source]
azure.servicebus.common.utils.renewable_start_time(renewable)[source]