Skip to content

Commit f06cb1a

Browse files
lsiddiqueeheathsvincenttran-msft
authored
Added sdk/storage/azure_storage_queue (Azure#2732)
Fixes Azure#2708 Added support for the 2018-03-28 Queue API. The following functions have been created on the new QueueClient, roughly following the pattern in the .Net SDK: ## QueueServiceClient The `QueueServiceClient` provides operations to interact with the Azure Storage Queue service at the account level. | Method | Parameters | Return Type | Description | |--------|------------|-------------|-------------| | `new` | `endpoint: &str`<br>`credential: Arc<dyn TokenCredential>`<br>`options: Option<QueueServiceClientOptions>` | `Result<Self>` | Creates a new QueueServiceClient using Entra ID authentication | | `endpoint` | `&self` | `&Url` | Returns the endpoint URL of the Azure storage account | | `queue_client` | `&self`<br>`queue_name: String` | `QueueClient` | Returns a new QueueClient instance for a specific queue | | `create_queue` | `&self`<br>`queue_name: &str`<br>`options: Option<QueueClientCreateOptions<'_>>` | `Result<Response<(), NoFormat>>` | Creates a new queue under the account | | `delete_queue` | `&self`<br>`queue_name: &str`<br>`options: Option<QueueClientDeleteOptions<'_>>` | `Result<Response<(), NoFormat>>` | Permanently deletes the specified queue | | `get_properties` | `&self`<br>`options: Option<QueueServiceClientGetPropertiesOptions<'_>>` | `Result<Response<QueueServiceProperties, XmlFormat>>` | Retrieves the properties of the queue service | | `set_properties` | `&self`<br>`queue_service_properties: RequestContent<QueueServiceProperties, XmlFormat>`<br>`options: Option<QueueServiceClientSetPropertiesOptions<'_>>` | `Result<Response<(), NoFormat>>` | Sets the properties of the queue service | | `list_queues` | `&self`<br>`options: Option<QueueServiceClientListQueuesOptions<'_>>` | `Result<PageIterator<Response<ListQueuesResponse, XmlFormat>>>` | Lists queues in the storage account with pagination | | `get_statistics` | `&self`<br>`options: Option<QueueServiceClientGetStatisticsOptions<'_>>` | `Result<Response<QueueServiceStats, XmlFormat>>` | Retrieves statistics related to replication for the Queue service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account | --- ## QueueClient The `QueueClient` provides operations to interact with a specific Azure Storage Queue. | Method | Parameters | Return Type | Description | |--------|------------|-------------|-------------| | `new` | `endpoint: &str`<br>`queue_name: &str`<br>`credential: Arc<dyn TokenCredential>`<br>`options: Option<QueueClientOptions>` | `Result<Self>` | Creates a new QueueClient using Entra ID authentication | | `endpoint` | `&self` | `&Url` | Returns the endpoint URL of the Azure storage account | | `queue_name` | `&self` | `&str` | Returns the name of the queue this client is associated with | ### Queue Management | Method | Parameters | Return Type | Description | |--------|------------|-------------|-------------| | `create` | `&self`<br>`options: Option<QueueClientCreateOptions<'_>>` | `Result<Response<(), NoFormat>>` | Creates a new queue | | `delete` | `&self`<br>`options: Option<QueueClientDeleteOptions<'_>>` | `Result<Response<(), NoFormat>>` | Permanently deletes the queue | | `exists` | `&self` | `Result<bool>` | Checks if the queue exists | | `clear` | `&self`<br>`options: Option<QueueClientClearOptions<'_>>` | `Result<Response<(), NoFormat>>` | Clears all messages in the queue | ### Metadata Operations | Method | Parameters | Return Type | Description | |--------|------------|-------------|-------------| | `set_metadata` | `&self`<br>`metadata: HashMap<String, String>`<br>`options: Option<QueueClientSetMetadataOptions<'_>>` | `Result<Response<(), NoFormat>>` | Sets the metadata for the queue | | `get_metadata` | `&self`<br>`options: Option<QueueClientGetMetadataOptions<'_>>` | `Result<Response<QueueClientGetMetadataResult, NoFormat>>` | Retrieves the metadata of the queue | ### Message Operations | Method | Parameters | Return Type | Description | |--------|------------|-------------|-------------| | `send_message` | `&self`<br>`queue_message: RequestContent<QueueMessage, XmlFormat>`<br>`options: Option<QueueClientSendMessageOptions<'_>>` | `Result<Response<SentMessage, XmlFormat>>` | Enqueues a message to the queue | | `receive_messages` | `&self`<br>`options: Option<QueueClientReceiveMessagesOptions<'_>>` | `Result<Response<ListOfReceivedMessage, XmlFormat>>` | Retrieves multiple messages from the front of the queue | | `peek_messages` | `&self`<br>`options: Option<QueueClientPeekMessagesOptions<'_>>` | `Result<Response<ListOfPeekedMessage, XmlFormat>>` | Peeks multiple messages without removing them | | `delete_message` | `&self`<br>`message_id: &str`<br>`pop_receipt: &str`<br>`options: Option<QueueClientDeleteMessageOptions<'_>>` | `Result<Response<(), NoFormat>>` | Deletes a specific message from the queue | | `update_message` | `&self`<br>`message_id: &str`<br>`pop_receipt: &str`<br>`visibility_timeout: i32`<br>`options: Option<QueueClientUpdateOptions<'_>>` | `Result<Response<(), NoFormat>>` | Updates a specific message in the queue | Examples of how to use each method has been provided in the `sdk/storage/examples/queue_client.rs` file. Recorded tests has also been pushed to the repo `Azure/azure-sdk-assets` and the `assets.json` updated. The client is generated using tsp-client using remote `Azure/azure-rest-api-specs` repo. - [ ] Merge Azure/azure-rest-api-specs#37739 into https://github.com/Azure/azure-rest-api-specs/tree/feature/azure-queue-storage-typespec and regenerate --------- Co-authored-by: Heath Stewart <[email protected]> Co-authored-by: Vincent Tran <[email protected]>
1 parent acecab2 commit f06cb1a

30 files changed

+4123
-1
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ members = [
2222
"sdk/canary/azure_canary",
2323
"sdk/storage/azure_storage_common",
2424
"sdk/storage/azure_storage_blob",
25+
"sdk/storage/azure_storage_queue",
2526
]
2627
exclude = [
2728
"eng/scripts",

sdk/storage/.dict.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ testcontainer
2727
uncommittedblobs
2828
westus
2929
yourtagname
30+
numofmessages
31+
peekonly

sdk/storage/azure_storage_blob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"AssetsRepoPrefixPath": "rust",
44
"Tag": "rust/azure_storage_blob_fc6c153d44",
55
"TagPrefix": "rust/azure_storage_blob"
6-
}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Release History
2+
3+
## 0.1.0 (Unreleased)
4+
5+
### Features Added
6+
7+
* Initial supported release.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "azure_storage_queue"
3+
version = "0.1.0"
4+
description = "Microsoft Azure Queue client library for Rust"
5+
readme = "README.md"
6+
authors.workspace = true
7+
edition.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
homepage = "https://github.com/azure/azure-sdk-for-rust"
12+
documentation = "https://docs.rs/azure_storage_queue"
13+
keywords = ["sdk", "azure", "storage", "queue", "queues"]
14+
categories = ["api-bindings"]
15+
16+
[features]
17+
default = ["azure_core/default"]
18+
19+
[dependencies]
20+
azure_core = { workspace = true, features = ["xml"] }
21+
serde = { workspace = true }
22+
23+
[lints]
24+
workspace = true
25+
26+
[dev-dependencies]
27+
azure_core_test.workspace = true
28+
azure_identity.workspace = true
29+
futures.workspace = true
30+
rand.workspace = true
31+
tokio = { workspace = true, features = ["macros"] }
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Azure Queue client library for Rust
2+
3+
Azure Queue Storage is a service for storing large numbers of messages.
4+
5+
[Source code] | [Package (crates.io)] | [API reference documentation] | [REST API documentation] | [Product documentation]
6+
7+
## Getting started
8+
9+
**⚠️ Note: The `azure_storage_queue` crate is currently under active development and not all features may be implemented or work as intended. This crate is in beta and not suitable for Production environments. For any general feedback or usage issues, please open a GitHub issue at <https://github.com/Azure/azure-sdk-for-rust/issues>.**
10+
11+
### Install the package
12+
13+
Install the Azure Storage Queue client library for Rust with [cargo]:
14+
15+
```sh
16+
cargo add azure_storage_queue
17+
```
18+
19+
### Prerequisites
20+
21+
* You must have an [Azure subscription] and an [Azure storage account] to use this package.
22+
23+
### Create a storage account
24+
25+
If you wish to create a new storage account, you can use the
26+
[Azure Portal], [Azure PowerShell], or [Azure CLI]:
27+
28+
```sh
29+
# Create a new resource group to hold the storage account -
30+
# if using an existing resource group, skip this step
31+
az group create --name my-resource-group --location westus2
32+
33+
# Create the storage account
34+
az storage account create -n my-storage-account-name -g my-resource-group
35+
```
36+
37+
#### Authenticate the client
38+
39+
In order to interact with the Azure Queue service, you'll need to create an instance of a client, `QueueClient`. The [Azure Identity] library makes it easy to add Microsoft Entra ID support for authenticating Azure SDK clients with their corresponding Azure services:
40+
41+
```rust no_run
42+
use azure_storage_queue::{QueueClient, QueueClientOptions};
43+
use azure_identity::DeveloperToolsCredential;
44+
45+
#[tokio::main]
46+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
47+
// Create a QueueClient that will authenticate through Microsoft Entra ID
48+
let credential = DeveloperToolsCredential::new(None)?;
49+
let queue_client = QueueClient::new(
50+
"https://<storage_account_name>.blob.core.windows.net/", // endpoint
51+
"queue-name", // queue name
52+
credential, // credential
53+
Some(QueueClientOptions::default()), // QueueClient options
54+
)?;
55+
Ok(())
56+
}
57+
```
58+
59+
#### Permissions
60+
61+
You may need to specify RBAC roles to access Queues via Microsoft Entra ID. Please see [Assign an Azure role for access to queue data] for more details.
62+
63+
## Examples
64+
65+
<!-- TODO: Uncomment the links below when the PR is merged -->
66+
You can find executable examples for all major SDK functions in:
67+
68+
* [queue_client.rs]<!--(https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_queue/samples/queue_client.rs)-->
69+
* [queue_service_client.rs]<!--(https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_queue/samples/queue_service_client.rs)-->
70+
71+
## Next steps
72+
73+
### Provide feedback
74+
75+
If you encounter bugs or have suggestions, [open an issue](https://github.com/Azure/azure-sdk-for-rust/issues).
76+
77+
## Contributing
78+
79+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [https://cla.microsoft.com](https://cla.microsoft.com).
80+
81+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You'll only need to do this once across all repos using our CLA.
82+
83+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
84+
85+
<!-- TODO: Uncomment the links below when the PR is merged -->
86+
<!-- LINKS -->
87+
[Azure subscription]: https://azure.microsoft.com/free/
88+
[Azure storage account]: https://learn.microsoft.com/azure/storage/common/storage-account-overview
89+
[Azure Portal]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal
90+
[Azure PowerShell]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell
91+
[Azure CLI]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli
92+
[cargo]: https://dev-doc.rust-lang.org/stable/cargo/commands/cargo.html
93+
[Azure Identity]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/identity/azure_identity
94+
<!--[API reference documentation]: https://docs.rs/crate/azure_storage_queue/latest-->
95+
<!--[Package (crates.io)]: https://crates.io/crates/azure_storage_queue-->
96+
[Source code]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_queue
97+
[REST API documentation]: https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api
98+
[Product documentation]: https://learn.microsoft.com/azure/storage/blobs/storage-blobs-overview
99+
[Assign an Azure role for access to queue data]: https://learn.microsoft.com/azure/storage/queues/assign-azure-role-data-access?tabs=portal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "rust",
4+
"Tag": "rust/azure_storage_queue_5f6f02d3be",
5+
"TagPrefix": "rust/azure_storage_queue"
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Storage Queue Examples
2+
3+
This directory contains a set of example for the use of the Storage Queue clients.
4+
5+
## Setup
6+
7+
The following environment variables need to be set:
8+
9+
- `AZURE_QUEUE_STORAGE_ACCOUNT_NAME=<storage_account_name>`

0 commit comments

Comments
 (0)