QueueServiceClient Class
- java.
lang. Object - com.
azure. storage. queue. QueueServiceClient
- com.
public final class QueueServiceClient
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 Synchronous Queue Service Client
QueueServiceClient client = new QueueServiceClientBuilder()
.connectionString("connectionstring")
.endpoint("endpoint")
.buildClient();
View QueueServiceClientBuilder for additional ways to construct the client.
Method Summary
Modifier and Type | Method and Description |
---|---|
Queue |
createQueue(String queueName)
Creates a queue in the storage account with the specified name and returns a Queue |
Response<Queue |
createQueueWithResponse(String queueName, Map<String,String> metadata, Duration timeout, Context context)
Creates a queue in the storage account with the specified name and metadata and returns a Queue |
void |
deleteQueue(String queueName)
Deletes a queue in the storage account |
Response<Void> |
deleteQueueWithResponse(String queueName, Duration timeout, Context context)
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 |
generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Consumer<String> stringToSignHandler, Context context)
Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues. |
String |
getAccountName()
Get associated account name. |
Http |
getHttpPipeline()
Gets the HttpPipeline powering this client. |
Queue |
getMessageEncoding()
Gets the message encoding the client is using. |
Queue |
getProperties()
Retrieves the properties of the storage account's Queue service. |
Response<Queue |
getPropertiesWithResponse(Duration timeout, Context context)
Retrieves the properties of the storage account's Queue service. |
Queue |
getQueueClient(String queueName)
Constructs a Queue |
String |
getQueueServiceUrl()
Get the url of the storage queue. |
Queue |
getServiceVersion()
Gets the service version the client is using. |
Queue |
getStatistics()
Retrieves the geo replication information about the Queue service. |
Response<Queue |
getStatisticsWithResponse(Duration timeout, Context context)
Retrieves the geo replication information about the Queue service. |
Paged |
listQueues()
Lists all queues in the storage account without their metadata. |
Paged |
listQueues(QueuesSegmentOptions options, Duration timeout, 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. |
Response<Void> |
setPropertiesWithResponse(QueueServiceProperties properties, Duration timeout, Context context)
Sets the properties for the storage account's Queue service. |
Methods inherited from java.lang.Object
Method Details
createQueue
public QueueClient createQueue(String queueName)
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:
Returns:
createQueueWithResponse
public Response
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:
Returns:
deleteQueue
public void deleteQueue(String queueName)
Deletes a queue in the storage account
Code Samples
Delete the queue "test"
client.deleteQueue("myqueue");
System.out.println("Complete deleting the queue.");
Parameters:
deleteQueueWithResponse
public Response
Deletes a queue in the storage account
Code 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:
Returns:
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.
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:
Returns:
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.
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:
Returns:
String
representing the SAS query parameters.generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Consumer
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.
Parameters:
Returns:
String
representing the SAS query parameters.getAccountName
public String getAccountName()
Get associated account name.
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
getMessageEncoding
public QueueMessageEncoding getMessageEncoding()
Gets the message encoding the client is using.
Returns:
getProperties
public QueueServiceProperties 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:
getPropertiesWithResponse
public Response
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:
Returns:
getQueueClient
public QueueClient getQueueClient(String queueName)
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:
Returns:
getQueueServiceUrl
public String getQueueServiceUrl()
Get the url of the storage queue.
Returns:
getServiceVersion
public QueueServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
getStatistics
public QueueServiceStatistics 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:
getStatisticsWithResponse
public Response
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:
Returns:
listQueues
public PagedIterable
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:
listQueues
public PagedIterable
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"), 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:
Returns:
setProperties
public void 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();
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:
setPropertiesWithResponse
public Response
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();
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:
Returns:
Applies to
Azure SDK for Java