A client to interact with the Queue Service at the account level.
This client provides operations to retrieve and configure the account properties as well as list, create and delete queues within the account. For operations relating to a specific queue, a client for this entity can be retrieved using the get_queue_client function.
For more optional configuration, please click here.
ConstructorQueueServiceClient(account_url: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, *, api_version: str | None = None, secondary_hostname: str | None = None, audience: str | None = None, **kwargs: Any)
Parameters Keyword-Only Parameters Examples
Creating the QueueServiceClient with an account url and credential.
from azure.storage.queue import QueueServiceClient
queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key)
Creating the QueueServiceClient with Default Azure Identity credentials.
# Get a token credential for authentication
from azure.identity import DefaultAzureCredential
token_credential = DefaultAzureCredential()
# Instantiate a QueueServiceClient using a token credential
from azure.storage.queue import QueueServiceClient
queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential)
Methods close
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
create_queueCreates a new queue under the specified account.
If a queue with the same name already exists, the operation fails. Returns a client with which to interact with the newly created queue.
delete_queueDeletes the specified queue and any messages it contains.
When a queue is successfully deleted, it is immediately marked for deletion and is no longer accessible to clients. The queue is later removed from the Queue service during garbage collection.
Note that deleting a queue is likely to take at least 40 seconds to complete. If an operation is attempted against the queue while it was being deleted, an ~azure.core.exceptions.HttpResponseError will be thrown.
from_connection_stringCreate QueueServiceClient from a Connection String.
get_queue_clientGet a client to interact with the specified queue.
The queue need not already exist.
get_service_propertiesGets the properties of a storage account's Queue service, including Azure Storage Analytics.
get_service_statsRetrieves statistics related to replication for the Queue service.
It is only available when read-access geo-redundant replication is enabled for the storage account.
With geo-redundant replication, Azure Storage maintains your data durable in two locations. In both locations, Azure Storage constantly maintains multiple healthy replicas of your data. The location where you read, create, update, or delete data is the primary storage account location. The primary location exists in the region you choose at the time you create an account via the Azure Management Azure classic portal, for example, North Central US. The location to which your data is replicated is the secondary location. The secondary location is automatically determined based on the location of the primary; it is in a second data center that resides in the same region as the primary location. Read-only access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account.
list_queuesReturns a generator to list the queues under the specified account.
The generator will lazily follow the continuation tokens returned by the service and stop when all queues have been returned.
set_service_propertiesSets the properties of a storage account's Queue service, including Azure Storage Analytics.
If an element (e.g. analytics_logging) is left as None, the existing settings on the service for that functionality are preserved.
closeThis method is to close the sockets opened by the client. It need not be used when using with a context manager.
close() -> None
create_queue
Creates a new queue under the specified account.
If a queue with the same name already exists, the operation fails. Returns a client with which to interact with the newly created queue.
create_queue(name: str, metadata: Dict[str, str] | None = None, *, timeout: int | None = None, **kwargs: Any) -> QueueClient
Parameters Keyword-Only Parameters Returns Examples
Create a queue in the service.
queue_service.create_queue("myqueueservice1")
delete_queue
Deletes the specified queue and any messages it contains.
When a queue is successfully deleted, it is immediately marked for deletion and is no longer accessible to clients. The queue is later removed from the Queue service during garbage collection.
Note that deleting a queue is likely to take at least 40 seconds to complete. If an operation is attempted against the queue while it was being deleted, an ~azure.core.exceptions.HttpResponseError will be thrown.
delete_queue(queue: QueueProperties | str, *, timeout: int | None = None, **kwargs: Any) -> None
Parameters Keyword-Only Parameters Returns Examples
Delete a queue in the service.
queue_service.delete_queue("myqueueservice1")
from_connection_string
Create QueueServiceClient from a Connection String.
from_connection_string(conn_str: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, *, api_version: str | None = None, secondary_hostname: str | None = None, audience: str | None = None, **kwargs: Any) -> Self
Parameters Keyword-Only Parameters Returns Examples
Creating the QueueServiceClient with a connection string.
from azure.storage.queue import QueueServiceClient
queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string)
get_queue_client
Get a client to interact with the specified queue.
The queue need not already exist.
get_queue_client(queue: QueueProperties | str, **kwargs: Any) -> QueueClient
Parameters Returns Examples
Get the queue client.
# Get the queue client to interact with a specific queue
queue = queue_service.get_queue_client(queue="myqueueservice2")
get_service_properties
Gets the properties of a storage account's Queue service, including Azure Storage Analytics.
get_service_properties(*, timeout: int | None = None, **kwargs: Any) -> Dict[str, Any]
Keyword-Only Parameters Returns Examples
Getting queue service properties.
properties = queue_service.get_service_properties()
get_service_stats
Retrieves statistics related to replication for the Queue service.
It is only available when read-access geo-redundant replication is enabled for the storage account.
With geo-redundant replication, Azure Storage maintains your data durable in two locations. In both locations, Azure Storage constantly maintains multiple healthy replicas of your data. The location where you read, create, update, or delete data is the primary storage account location. The primary location exists in the region you choose at the time you create an account via the Azure Management Azure classic portal, for example, North Central US. The location to which your data is replicated is the secondary location. The secondary location is automatically determined based on the location of the primary; it is in a second data center that resides in the same region as the primary location. Read-only access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account.
get_service_stats(*, timeout: int | None = None, **kwargs: Any) -> Dict[str, Any]
Keyword-Only Parameters Returns list_queues
Returns a generator to list the queues under the specified account.
The generator will lazily follow the continuation tokens returned by the service and stop when all queues have been returned.
list_queues(name_starts_with: str | None = None, include_metadata: bool | None = False, *, results_per_page: int | None = None, timeout: int | None = None, **kwargs: Any) -> ItemPaged[QueueProperties]
Parameters Keyword-Only Parameters Returns Examples
List queues in the service.
# List all the queues in the service
list_queues = queue_service.list_queues()
for queue in list_queues:
print(queue)
# List the queues in the service that start with the name "my"
list_my_queues = queue_service.list_queues(name_starts_with="my")
for queue in list_my_queues:
print(queue)
set_service_properties
Sets the properties of a storage account's Queue service, including Azure Storage Analytics.
If an element (e.g. analytics_logging) is left as None, the existing settings on the service for that functionality are preserved.
set_service_properties(analytics_logging: QueueAnalyticsLogging | None = None, hour_metrics: Metrics | None = None, minute_metrics: Metrics | None = None, cors: List[CorsRule] | None = None, *, timeout: int | None = None, **kwargs: Any) -> None
Parameters Keyword-Only Parameters Examples
Setting queue service properties.
# Create service properties
from azure.storage.queue import QueueAnalyticsLogging, Metrics, CorsRule, RetentionPolicy
# Create logging settings
logging = QueueAnalyticsLogging(
read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)
)
# Create metrics for requests statistics
hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))
minute_metrics = Metrics(
enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)
)
# Create CORS rules
cors_rule1 = CorsRule(["www.xyz.com"], ["GET"])
allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"]
allowed_methods = ["GET", "PUT"]
max_age_in_seconds = 500
exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"]
allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"]
cors_rule2 = CorsRule(
allowed_origins,
allowed_methods,
max_age_in_seconds=max_age_in_seconds,
exposed_headers=exposed_headers,
allowed_headers=allowed_headers,
)
cors = [cors_rule1, cors_rule2]
# Set the service properties
queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors)
Attributes api_version
The version of the Storage API used for requests.
Returns location_modeThe location mode that the client is currently using.
By default this will be "primary". Options include "primary" and "secondary".
Returns primary_endpointThe full primary endpoint URL.
Returns primary_hostnameThe hostname of the primary endpoint.
Returns secondary_endpointThe full secondary endpoint URL if configured.
If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
Returns Exceptions secondary_hostnameThe hostname of the secondary endpoint.
If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
Returns urlThe full endpoint URL to this entity, including SAS token if used.
This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.
ReturnsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4