QueueServiceAsyncClient Class

  • java.lang.Object
    • com.azure.storage.queue.QueueServiceAsyncClient

public final class QueueServiceAsyncClient

This class provides a client that contains all the operations for interacting with a queue account in Azure Storage. Operations allowed by the client are creating, listing, and deleting queues, retrieving and updating properties of the account, and retrieving statistics of the account.

Instantiating an Asynchronous Queue Service Client

QueueServiceAsyncClient client = new QueueServiceClientBuilder()
     .connectionString("connectionstring")
     .endpoint("endpoint")
     .buildAsyncClient();

View QueueServiceClientBuilder for additional ways to construct the client.

Method Summary

Modifier and Type Method and Description
Mono<QueueAsyncClient> createQueue(String queueName)

Creates a queue in the storage account with the specified name and returns a QueueAsyncClient to interact with it.

Mono<Response<QueueAsyncClient>> createQueueWithResponse(String queueName, Map<String,String> metadata)

Creates a queue in the storage account with the specified name and metadata and returns a QueueAsyncClient to interact with it.

Mono<Void> deleteQueue(String queueName)

Deletes a queue in the storage account

Mono<Response<Void>> deleteQueueWithResponse(String queueName)

Deletes a queue in the storage account

String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)

Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Context context)

Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

String getAccountName()

Get associated account name.

HttpPipeline getHttpPipeline()

Gets the HttpPipeline powering this client.

QueueMessageEncoding getMessageEncoding()

Gets the message encoding the client is using.

Mono<QueueServiceProperties> getProperties()

Retrieves the properties of the storage account's Queue service.

Mono<Response<QueueServiceProperties>> getPropertiesWithResponse()

Retrieves the properties of the storage account's Queue service.

QueueAsyncClient getQueueAsyncClient(String queueName)

Constructs a QueueAsyncClient that interacts with the specified queue.

String getQueueServiceUrl()
QueueServiceVersion getServiceVersion()

Gets the service version the client is using.

Mono<QueueServiceStatistics> getStatistics()

Retrieves the geo replication information about the Queue service.

Mono<Response<QueueServiceStatistics>> getStatisticsWithResponse()

Retrieves the geo replication information about the Queue service.

PagedFlux<QueueItem> listQueues()

Lists all queues in the storage account without their metadata.

PagedFlux<QueueItem> listQueues(QueuesSegmentOptions options)

Lists the queues in the storage account that pass the filter.

Mono<Void> setProperties(QueueServiceProperties properties)

Sets the properties for the storage account's Queue service.

Mono<Response<Void>> setPropertiesWithResponse(QueueServiceProperties properties)

Sets the properties for the storage account's Queue service.

Methods inherited from java.lang.Object

Method Details

createQueue

public Mono createQueue(String queueName)

Creates a queue in the storage account with the specified name and returns a QueueAsyncClient to interact with it.

Code Samples

Create the queue "test"

client.createQueue("myqueue").subscribe(
     response -> {
     },
     error -> System.err.print(error.toString()),
     () -> System.out.println("Complete creating the queue!")
 );

Parameters:

queueName - Name of the queue

Returns:

createQueueWithResponse

public Mono<>> createQueueWithResponse(String queueName, Map metadata)

Creates a queue in the storage account with the specified name and metadata and returns a QueueAsyncClient to interact with it.

Code Samples

Create the queue "test" with metadata "queue:metadata"

client.createQueueWithResponse("myqueue", Collections.singletonMap("queue", "metadata"))
     .subscribe(
         response -> System.out.printf("Creating the queue with status code %d", response.getStatusCode()),
         error -> System.err.print(error.toString()),
         () -> System.out.println("Complete creating the queue!")
     );

Parameters:

queueName - Name of the queue
metadata - Metadata to associate with the queue. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.

Returns:

A response containing the QueueAsyncClient and the status of creating the queue

deleteQueue

public Mono deleteQueue(String queueName)

Deletes a queue in the storage account

Code Samples

Delete the queue "test"

client.deleteQueue("myshare").subscribe(
     response -> System.out.println("Deleting the queue completed.")
 );

Parameters:

queueName - Name of the queue

Returns:

An empty response

deleteQueueWithResponse

public Mono<>> deleteQueueWithResponse(String queueName)

Deletes a queue in the storage account

Code Samples

Delete the queue "test"

client.deleteQueueWithResponse("myshare").subscribe(
     response -> System.out.println("Deleting the queue completed with status code: " + response.getStatusCode())
 );

Parameters:

queueName - Name of the queue

Returns:

A response that only contains headers and response status code

generateAccountSas

public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)

Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

Note : The client must be authenticated via StorageSharedKeyCredential

See AccountSasSignatureValues for more information on how to construct an account SAS.

The snippet below generates a SAS that lasts for two days and gives the user read and list access to queues and file shares.

AccountSasPermission permissions = new AccountSasPermission()
     .setListPermission(true)
     .setReadPermission(true);
 AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true).setObject(true);
 AccountSasService services = new AccountSasService().setQueueAccess(true).setFileAccess(true);
 OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));

 AccountSasSignatureValues sasValues =
     new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);

 // Client must be authenticated via StorageSharedKeyCredential
 String sas = queueServiceAsyncClient.generateAccountSas(sasValues);

Parameters:

accountSasSignatureValues - AccountSasSignatureValues

Returns:

A String representing the SAS query parameters.

generateAccountSas

public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Context context)

Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

Note : The client must be authenticated via StorageSharedKeyCredential

See AccountSasSignatureValues for more information on how to construct an account SAS.

The snippet below generates a SAS that lasts for two days and gives the user read and list access to queues and file shares.

AccountSasPermission permissions = new AccountSasPermission()
     .setListPermission(true)
     .setReadPermission(true);
 AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true).setObject(true);
 AccountSasService services = new AccountSasService().setQueueAccess(true).setFileAccess(true);
 OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));

 AccountSasSignatureValues sasValues =
     new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);

 // Client must be authenticated via StorageSharedKeyCredential
 String sas = queueServiceAsyncClient.generateAccountSas(sasValues, new Context("key", "value"));

Parameters:

accountSasSignatureValues - AccountSasSignatureValues
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

getAccountName

public String getAccountName()

Get associated account name.

Returns:

account name associated with this storage resource.

getHttpPipeline

public HttpPipeline getHttpPipeline()

Gets the HttpPipeline powering this client.

Returns:

The pipeline.

getMessageEncoding

public QueueMessageEncoding getMessageEncoding()

Gets the message encoding the client is using.

Returns:

the message encoding the client is using.

getProperties

public Mono getProperties()

Retrieves the properties of the storage account's Queue service. The properties range from storage analytics and metric to CORS (Cross-Origin Resource Sharing).

Code Samples

Retrieve Queue service properties

client.getProperties()
     .subscribe(properties -> {
         System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b",
             properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
     });

For more information, see the Azure Docs.

Returns:

Storage account QueueServiceProperties

getPropertiesWithResponse

public Mono<>> getPropertiesWithResponse()

Retrieves the properties of the storage account's Queue service. The properties range from storage analytics and metric to CORS (Cross-Origin Resource Sharing).

Code Samples

Retrieve Queue service properties

client.getPropertiesWithResponse()
     .subscribe(response -> {
         QueueServiceProperties properties = response.getValue();
         System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b",
             properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
     });

For more information, see the Azure Docs.

Returns:

A response containing the Storage account QueueServiceProperties

getQueueAsyncClient

public QueueAsyncClient getQueueAsyncClient(String queueName)

Constructs a QueueAsyncClient that interacts with the specified queue. This will not create the queue in the storage account if it doesn't exist.

Parameters:

queueName - Name of the queue

Returns:

QueueAsyncClient that interacts with the specified queue

getQueueServiceUrl

public String getQueueServiceUrl()

Returns:

the URL of the storage queue

getServiceVersion

public QueueServiceVersion getServiceVersion()

Gets the service version the client is using.

Returns:

the service version the client is using.

getStatistics

public Mono getStatistics()

Retrieves the geo replication information about the Queue service.

Code Samples

Retrieve the geo replication information

client.getStatistics()
     .subscribe(stats -> {
         System.out.printf("Geo replication status: %s, Last synced: %s",
             stats.getGeoReplication().getStatus(), stats.getGeoReplication().getLastSyncTime());
     });

For more information, see the Azure Docs.

Returns:

The geo replication information about the Queue service

getStatisticsWithResponse

public Mono<>> getStatisticsWithResponse()

Retrieves the geo replication information about the Queue service.

Code Samples

Retrieve the geo replication information

client.getStatisticsWithResponse()
     .subscribe(response -> {
         QueueServiceStatistics stats = response.getValue();
         System.out.printf("Geo replication status: %s, Last synced: %s",
             stats.getGeoReplication().getStatus(), stats.getGeoReplication().getLastSyncTime());
     });

For more information, see the Azure Docs.

Returns:

A response containing the geo replication information about the Queue service

listQueues

public PagedFlux listQueues()

Lists all queues in the storage account without their metadata.

Code Samples

List all queues in the account

client.listQueues().subscribe(
     queueItem -> System.out.printf("Queue %s exists in the account", queueItem.getName()),
     error -> System.err.print(error.toString()),
     () -> System.out.println("Complete listing the queues!")
 );

For more information, see the Azure Docs.

Returns:

QueueItem in the storage account

listQueues

public PagedFlux listQueues(QueuesSegmentOptions options)

Lists the queues in the storage account that pass the filter. Pass true to setIncludeMetadata(boolean includeMetadata) to have metadata returned for the queues.

Code Samples

List all queues that begin with "azure"

client.listQueues(new QueuesSegmentOptions().setPrefix("azure")).subscribe(
     queueItem -> System.out.printf("Queue %s exists in the account and has metadata %s",
         queueItem.getName(), queueItem.getMetadata()),
     error -> System.err.print(error.toString()),
     () -> System.out.println("Complete listing the queues!")
 );

For more information, see the Azure Docs.

Parameters:

options - Options for listing queues

Returns:

QueueItem in the storage account that satisfy the filter requirements

setProperties

public Mono setProperties(QueueServiceProperties properties)

Sets the properties for the storage account's Queue service. The properties range from storage analytics and metric to CORS (Cross-Origin Resource Sharing). To maintain the CORS in the Queue service pass a null value for getCors(). To disable all CORS in the Queue service pass an empty list for getCors().

Code Sample

Clear CORS in the Queue service

QueueServiceProperties properties = client.getProperties().block();
 client.setProperties(properties)
     .doOnSuccess(response -> System.out.println("Setting Queue service properties completed."));

Enable Minute and Hour Metrics

QueueServiceProperties properties = client.getProperties().block();
 properties.getMinuteMetrics().setEnabled(true);
 properties.getHourMetrics().setEnabled(true);
 client.setProperties(properties).subscribe(
     response -> System.out.println("Setting Queue service properties completed."));

For more information, see the Azure Docs.

Parameters:

properties - Storage account Queue service properties

Returns:

An empty response

setPropertiesWithResponse

public Mono<>> setPropertiesWithResponse(QueueServiceProperties properties)

Sets the properties for the storage account's Queue service. The properties range from storage analytics and metric to CORS (Cross-Origin Resource Sharing). To maintain the CORS in the Queue service pass a null value for getCors(). To disable all CORS in the Queue service pass an empty list for getCors().

Code Sample

Clear CORS in the Queue service

QueueServiceProperties properties = client.getProperties().block();
 client.setPropertiesWithResponse(properties)
     .subscribe(response -> System.out.printf("Setting Queue service properties completed with status code %d",
         response.getStatusCode()));

Enable Minute and Hour Metrics

QueueServiceProperties properties = client.getProperties().block();
 properties.getMinuteMetrics().setEnabled(true);
 properties.getHourMetrics().setEnabled(true);
 client.setPropertiesWithResponse(properties)
     .subscribe(response -> System.out.printf("Setting Queue service properties completed with status code %d",
         response.getStatusCode()));

For more information, see the Azure Docs.

Parameters:

properties - Storage account Queue service properties

Returns:

A response that only contains headers and response status code

Applies to