Class QueueServiceClient
Instantiating an Synchronous Queue Service Client
QueueServiceClient client = new QueueServiceClientBuilder() .connectionString("connectionstring") .endpoint("endpoint") .buildClient();
View this
for additional ways to construct the client.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreateQueue
(String queueName) Creates a queue in the storage account with the specified name and returns a QueueClient to interact with it.com.azure.core.http.rest.Response
<QueueClient> createQueueWithResponse
(String queueName, Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a queue in the storage account with the specified name and metadata and returns a QueueClient to interact with it.void
deleteQueue
(String queueName) Deletes a queue in the storage accountcom.azure.core.http.rest.Response
<Void> deleteQueueWithResponse
(String queueName, Duration timeout, com.azure.core.util.Context context) Deletes a queue in the storage accountgenerateAccountSas
(AccountSasSignatureValues accountSasSignatureValues) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.generateAccountSas
(AccountSasSignatureValues accountSasSignatureValues, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.generateAccountSas
(AccountSasSignatureValues accountSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Get associated account name.com.azure.core.http.HttpPipeline
Gets theHttpPipeline
powering this client.Gets the message encoding the client is using.Retrieves the properties of the storage account's Queue service.com.azure.core.http.rest.Response
<QueueServiceProperties> getPropertiesWithResponse
(Duration timeout, com.azure.core.util.Context context) Retrieves the properties of the storage account's Queue service.getQueueClient
(String queueName) Constructs a QueueClient that interacts with the specified queue.Get the url of the storage queue.Gets the service version the client is using.Retrieves the geo replication information about the Queue service.com.azure.core.http.rest.Response
<QueueServiceStatistics> getStatisticsWithResponse
(Duration timeout, com.azure.core.util.Context context) Retrieves the geo replication information about the Queue service.com.azure.core.http.rest.PagedIterable
<QueueItem> Lists all queues in the storage account without their metadata.com.azure.core.http.rest.PagedIterable
<QueueItem> listQueues
(QueuesSegmentOptions options, Duration timeout, com.azure.core.util.Context context) Lists the queues in the storage account that pass the filter.void
setProperties
(QueueServiceProperties properties) Sets the properties for the storage account's Queue service.com.azure.core.http.rest.Response
<Void> setPropertiesWithResponse
(QueueServiceProperties properties, Duration timeout, com.azure.core.util.Context context) Sets the properties for the storage account's Queue service.
-
Method Details
-
getQueueServiceUrl
Get the url of the storage queue.- Returns:
- the URL of the storage queue
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
getMessageEncoding
Gets the message encoding the client is using.- Returns:
- the message encoding the client is using.
-
getQueueClient
Constructs a QueueClient 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:
- QueueClient that interacts with the specified queue
-
createQueue
Creates a queue in the storage account with the specified name and returns a QueueClient to interact with it.Code Samples
Create the queue "test"
client.createQueue("myqueue"); System.out.println("Complete creating queue.");
- Parameters:
queueName
- Name of the queue- Returns:
- A response containing the QueueClient and the status of creating the queue
- Throws:
QueueStorageException
- If a queue with the same name and different metadata already exists
-
createQueueWithResponse
public com.azure.core.http.rest.Response<QueueClient> createQueueWithResponse(String queueName, Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a queue in the storage account with the specified name and metadata and returns a QueueClient to interact with it.Code Samples
Create the queue "test" with metadata "queue:metadata"
Response<QueueClient> response = client.createQueueWithResponse("myqueue", Collections.singletonMap("queue", "metadata"), Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete creating queue with status code: " + response.getStatusCode());
- Parameters:
queueName
- Name of the queuemetadata
- 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.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the QueueClient and the status of creating the queue
- Throws:
QueueStorageException
- If a queue with the same name and different metadata already existsRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
deleteQueue
Deletes a queue in the storage accountCode Samples
Delete the queue "test"
client.deleteQueue("myqueue"); System.out.println("Complete deleting the queue.");
- Parameters:
queueName
- Name of the queue- Throws:
QueueStorageException
- If the queue doesn't exist
-
deleteQueueWithResponse
public com.azure.core.http.rest.Response<Void> deleteQueueWithResponse(String queueName, Duration timeout, com.azure.core.util.Context context) Deletes a queue in the storage accountCode Samples
Delete the queue "test"
Response<Void> response = client.deleteQueueWithResponse("myqueue", Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete deleting the queue with status code: " + response.getStatusCode());
- Parameters:
queueName
- Name of the queuetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the status of deleting the queue
- Throws:
QueueStorageException
- If the queue doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
listQueues
Lists all queues in the storage account without their metadata.Code Samples
List all queues in the account
client.listQueues().forEach( queueItem -> System.out.printf("Queue %s exists in the account", queueItem.getName()) );
For more information, see the Azure Docs.
- Returns:
Queues
in the storage account
-
listQueues
public com.azure.core.http.rest.PagedIterable<QueueItem> listQueues(QueuesSegmentOptions options, Duration timeout, com.azure.core.util.Context context) Lists the queues in the storage account that pass the filter. Pass true toincludeMetadata
to have metadata returned for the queues.Code Samples
List all queues that begin with "azure"
client.listQueues(new QueuesSegmentOptions().setPrefix("azure"), Duration.ofSeconds(1), new Context(key1, value1)).forEach( queueItem -> System.out.printf("Queue %s exists in the account and has metadata %s", queueItem.getName(), queueItem.getMetadata()) );
For more information, see the Azure Docs.
- Parameters:
options
- Options for listing queues. If iterating by page, the page size passed to byPage methods such as *ContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
Queues
in the storage account that satisfy the filter requirements- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
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
QueueServiceProperties properties = client.getProperties(); 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 Queue service properties
-
getPropertiesWithResponse
public com.azure.core.http.rest.Response<QueueServiceProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context) 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
QueueServiceProperties properties = client.getPropertiesWithResponse(Duration.ofSeconds(1), new Context(key1, value1)).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.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the Storage account Queue service properties
- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
setProperties
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 anull
value forCORS
. To disable all CORS in the Queue service pass an empty list forCORS
.Code Sample
Clear CORS in the Queue service
QueueServiceProperties properties = client.getProperties(); properties.setCors(Collections.emptyList()); client.setProperties(properties); System.out.println("Setting Queue service properties completed.");
Enable Minute and Hour Metrics
QueueServiceProperties properties = client.getProperties(); properties.getMinuteMetrics().setEnabled(true); properties.getMinuteMetrics().setIncludeApis(true); properties.getMinuteMetrics().setRetentionPolicy(new QueueRetentionPolicy().setDays(7).setEnabled(true)); properties.getHourMetrics().setEnabled(true); properties.getHourMetrics().setIncludeApis(true); properties.getHourMetrics().setRetentionPolicy(new QueueRetentionPolicy().setDays(7).setEnabled(true)); client.setProperties(properties); System.out.println("Setting Queue service properties completed.");
For more information, see the Azure Docs.
- Parameters:
properties
- Storage account Queue service properties- Throws:
QueueStorageException
- When one of the following is true- A CORS rule is missing one of its fields
- More than five CORS rules will exist for the Queue service
- Size of all CORS rules exceeds 2KB
-
Length of
allowed headers
,exposed headers
, orallowedOrigins() allowed origins
exceeds 256 characters. Allowed methods
isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or PUT
-
setPropertiesWithResponse
public com.azure.core.http.rest.Response<Void> setPropertiesWithResponse(QueueServiceProperties properties, Duration timeout, com.azure.core.util.Context context) 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 anull
value forCORS
. To disable all CORS in the Queue service pass an empty list forCORS
.Code Sample
Clear CORS in the Queue service
QueueServiceProperties properties = client.getProperties(); properties.setCors(Collections.emptyList()); Response<Void> response = client.setPropertiesWithResponse(properties, Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Setting Queue service properties completed with status code %d", response.getStatusCode());
Enable Minute and Hour Metrics
QueueServiceProperties properties = client.getProperties(); properties.getMinuteMetrics().setEnabled(true); properties.getMinuteMetrics().setIncludeApis(true); properties.getMinuteMetrics().setRetentionPolicy(new QueueRetentionPolicy().setDays(7).setEnabled(true)); properties.getHourMetrics().setEnabled(true); properties.getHourMetrics().setIncludeApis(true); properties.getHourMetrics().setRetentionPolicy(new QueueRetentionPolicy().setDays(7).setEnabled(true)); Response<Void> response = client.setPropertiesWithResponse(properties, Duration.ofSeconds(1), new Context(key1, value1)); 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 propertiestimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- When one of the following is true- A CORS rule is missing one of its fields
- More than five CORS rules will exist for the Queue service
- Size of all CORS rules exceeds 2KB
-
Length of
allowed headers
,exposed headers
, orallowed origins
exceeds 256 characters. Allowed methods
isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or PUT
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
getStatistics
Retrieves the geo replication information about the Queue service.Code Samples
Retrieve the geo replication information
QueueServiceStatistics stats = client.getStatistics(); 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 com.azure.core.http.rest.Response<QueueServiceStatistics> getStatisticsWithResponse(Duration timeout, com.azure.core.util.Context context) Retrieves the geo replication information about the Queue service.Code Samples
Retrieve the geo replication information
QueueServiceStatistics stats = client.getStatisticsWithResponse(Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Geo replication status: %s, Last synced: %s", stats.getGeoReplication().getStatus(), stats.getGeoReplication().getLastSyncTime());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the geo replication information about the Queue service
- Throws:
RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
getAccountName
Get associated account name.- Returns:
- account name associated with this storage resource.
-
getHttpPipeline
public com.azure.core.http.HttpPipeline getHttpPipeline()Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-
generateAccountSas
Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Note : The client must be authenticated via
StorageSharedKeyCredential
See
AccountSasSignatureValues
for more information on how to construct an account SAS.Generating an account SAS
The snippet below generates an AccountSasSignatureValues object that lasts for two days and gives the user read and list access to queue 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 = queueServiceClient.generateAccountSas(sasValues);
- Parameters:
accountSasSignatureValues
-AccountSasSignatureValues
- Returns:
- A
String
representing the SAS query parameters.
-
generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Note : The client must be authenticated via
StorageSharedKeyCredential
See
AccountSasSignatureValues
for more information on how to construct an account SAS.Generating an account SAS
The snippet below generates an AccountSasSignatureValues object that lasts for two days and gives the user read and list access to queue 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 = queueServiceClient.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.
-
generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Note : The client must be authenticated via
StorageSharedKeyCredential
See
AccountSasSignatureValues
for more information on how to construct an account SAS.- Parameters:
accountSasSignatureValues
-AccountSasSignatureValues
stringToSignHandler
- For debugging purposes only. Returns the string to sign that was used to generate the signature.context
- Additional context that is passed through the code when generating a SAS.- Returns:
- A
String
representing the SAS query parameters.
-