Skip to content

Commit 3e747c6

Browse files
committed
Initial implementation of the queue sdk (#2730)
Fixes #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: queue_client: new create create_if_not_exists clear delete delete_if_exists delete_message exists get_metadata get_properties enqueue_message dequeue_message dequeue_messages peek_message peek_messages set_metadata update_message get_access_policy set_access_policy queue_service_client: new create_queue delete_queue get_properties set_properties list_queues_segment (paginated) 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.
1 parent 258986c commit 3e747c6

36 files changed

+4043
-4
lines changed

Cargo.lock

Lines changed: 18 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
@@ -19,6 +19,7 @@ members = [
1919
"sdk/template/azure_template",
2020
"sdk/storage/azure_storage_common",
2121
"sdk/storage/azure_storage_blob",
22+
"sdk/storage/azure_storage_queue",
2223
]
2324
exclude = [
2425
"eng/scripts",

eng/emitter-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"@typespec/versioning": "0.71.0",
1515
"@typespec/xml": "0.71.0"
1616
}
17-
}
17+
}

sdk/storage/.dict.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ testblob1
2424
testblob2
2525
testblob3
2626
testblob4
27+
numofmessages
28+
peekonly

sdk/storage/assets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
4-
"Tag": "rust/azure_storage_blob_a55c38eec2",
5-
"TagPrefix": "rust/azure_storage_blob"
6-
}
4+
"Tag": "rust/azure_storage_79cfa5e62f",
5+
"TagPrefix": "rust/azure_storage"
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 (2025-06-17)
4+
5+
### Features Added
6+
7+
* Initial supported release.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 = ["reqwest"]
18+
reqwest = ["dep:reqwest"]
19+
20+
[dependencies]
21+
azure_core = { workspace = true, features = ["xml"] }
22+
quick-xml.workspace = true
23+
rand.workspace = true
24+
reqwest = { workspace = true, optional = true }
25+
serde = { workspace = true }
26+
serde_json = { workspace = true }
27+
time = { workspace = true }
28+
typespec_client_core = { workspace = true, features = ["derive"] }
29+
30+
[lints]
31+
workspace = true
32+
33+
[dev-dependencies]
34+
azure_core_test.workspace = true
35+
azure_identity.workspace = true
36+
futures.workspace = true
37+
tokio = { workspace = true, features = ["macros"] }
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 [here](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::clients::{QueueClient, QueueClientOptions};
43+
use azure_identity::DefaultAzureCredential;
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 = DefaultAzureCredential::new()?;
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+
## Features
64+
65+
The following methods are available on the ```QueueClient``` class:
66+
67+
- ```new```: Create a new instance of the ```QueueClient```.
68+
- ```create```: Creates a new queue, will fail if the queue already exists.
69+
- ```create_if_not_exists```: Creates a new queue, will _not_ fail if the queue already exists.
70+
- ```delete```: Deletes a queue, will fail if the queue does not exist.
71+
- ```delete_if_exists```: Deletes a queue, will _not_ fail if the queue does not exist.
72+
- ```delete_message```: Deletes a single message from the queue.
73+
- ```delete_messages```: Deletes all the messages in a queue. Requires Account Owner permission or it will fail.
74+
- ```exists```: Returns bool representing whether the queue exists or not.
75+
- ```get_metadata```: Returns metadata for the queue.
76+
- ```get_properties```: Returns the properties of the queue service.
77+
- ```peek_message```: Peeks a single message from the front of the queue without removing it.
78+
- ```peek_messages```: Peeks multiple messages from the front of the queue without removing them.
79+
- ```receive_message```: Receive a single message from the queue.
80+
- ```receive_messages```: Receive multiple messages from the queue. The number of messages to return is determined by the ```AzureQueueStorageMessagesOperationsClientDequeueOptions::number_of_messages``` property.
81+
- ```send_message```: Sends a message to the queue.
82+
- ```set_metadata```: Sets metadata on the queue.
83+
- ```update_message```: Updates a specific message in the queue.
84+
85+
## Examples
86+
87+
<!-- TODO: Update the link below when the PR is merged -->
88+
Executable examples of all the functions provided by this SDK can be found in the [queue_client.rs]<!--(https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_queue/examples/queue_client.rs)--> file in the examples directory.
89+
90+
## Next steps
91+
92+
### Provide feedback
93+
94+
If you encounter bugs or have suggestions, [open an issue](https://github.com/Azure/azure-sdk-for-rust/issues).
95+
96+
## Contributing
97+
98+
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).
99+
100+
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.
101+
102+
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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
103+
104+
<!-- TODO: Update the links below when the crate is published -->
105+
<!-- LINKS -->
106+
[Azure subscription]: https://azure.microsoft.com/free/
107+
[Azure storage account]: https://learn.microsoft.com/azure/storage/common/storage-account-overview
108+
[Azure Portal]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal
109+
[Azure PowerShell]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell
110+
[Azure CLI]: https://learn.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli
111+
[cargo]: https://dev-doc.rust-lang.org/stable/cargo/commands/cargo.html
112+
[Azure Identity]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/identity/azure_identity
113+
<!--[API reference documentation]: https://docs.rs/crate/azure_storage_queue/latest-->
114+
<!--[Package (crates.io)]: https://crates.io/crates/azure_storage_queue-->
115+
[Source code]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_queue
116+
[REST API documentation]: https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api
117+
[Product documentation]: https://learn.microsoft.com/azure/storage/blobs/storage-blobs-overview
118+
[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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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=https://<storage_account_name>.queue.core.windows.net/ - needs to include "https://" and trailing '/'
10+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub fn get_endpoint() -> String {
2+
// Retrieve the storage account endpoint from environment variable.
3+
let endpoint = std::env::var("AZURE_QUEUE_STORAGE_ACCOUNT");
4+
let endpoint = match endpoint {
5+
Ok(url) => url,
6+
Err(_) => {
7+
eprintln!("Environment variable AZURE_QUEUE_STORAGE_ACCOUNT is not set");
8+
std::process::exit(1);
9+
}
10+
};
11+
12+
// Validate endpoint format
13+
if !endpoint.ends_with("/") || !endpoint.starts_with("https://") {
14+
eprintln!("Endpoint must start with 'https://' and end with '/'");
15+
std::process::exit(1);
16+
}
17+
endpoint
18+
}

0 commit comments

Comments
 (0)