Expand description
§Azure Queue client library for Rust
Azure Queue Storage is a service for storing large numbers of messages.
Source code | Package (crates.io) | API reference documentation | REST API documentation | Product documentation
§Getting started
§Install the package
Install the Azure Storage Queue client library for Rust with cargo:
cargo add azure_storage_queue§Prerequisites
- You must have an Azure subscription and an Azure storage account to use this package.
§Create a storage account
If you wish to create a new storage account, you can use the Azure Portal, Azure PowerShell, or Azure CLI:
# Create a new resource group to hold the storage account.
# Skip this step if using an existing resource group.
az group create --name my-resource-group --location westus2
# Create the storage account
az storage account create -n my-storage-account-name -g my-resource-group§Authenticate the client
In order to interact with the Azure Queue service, you’ll need to create an instance of a client, QueueClient or QueueServiceClient. QueueServiceClient is the recommended entry point. Construct it once using QueueServiceClient::new(), then call QueueServiceClient::queue_client() to get a QueueClient. If you already have a fully-formed (for example, SAS-scoped) URL for a single queue, call QueueClient::new() with that URL directly instead.
The Azure Identity library makes it easy to add Microsoft Entra ID support for authenticating Azure SDK clients with their corresponding Azure services:
use azure_core::http::Url;
use azure_storage_queue::QueueServiceClient;
use azure_identity::DeveloperToolsCredential;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a QueueServiceClient that will authenticate through Microsoft Entra ID
let credential = DeveloperToolsCredential::new(None)?;
let service_url = Url::parse("https://<storage_account_name>.queue.core.windows.net/")?;
let service_client = QueueServiceClient::new(service_url, Some(credential), None)?;
// Derive a queue client by name.
let queue_client = service_client.queue_client("<queue_name>")?;
Ok(())
}§Permissions
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.
§Examples
You can find executable examples for all major SDK functions in:
- queue_hello_world.rs - Getting started: create a queue, send and receive messages
- queue_client.rs - Queue-level operations: metadata, send/peek/receive/delete, TTL/visibility options
- queue_service_client.rs - Service-level operations: list queues, service properties, statistics
- access_policy.rs - Set and get queue access policies (stored access policies for SAS)
- queue_storage_logging.rs - Logging and OpenTelemetry distributed tracing
§Send a message
use azure_core::http::Url;
use azure_storage_queue::{models::QueueMessage, QueueServiceClient};
use azure_identity::DeveloperToolsCredential;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credential = DeveloperToolsCredential::new(None)?;
let service_url = Url::parse("https://<storage_account_name>.queue.core.windows.net/")?;
let service_client = QueueServiceClient::new(service_url, Some(credential), None)?;
let queue_client = service_client.queue_client("<queue_name>")?;
let message = QueueMessage {
message_text: Some("hello world".to_string()),
};
queue_client.send_message(message.try_into()?, None).await?;
Ok(())
}§Receive messages
use azure_core::http::Url;
use azure_storage_queue::QueueServiceClient;
use azure_identity::DeveloperToolsCredential;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credential = DeveloperToolsCredential::new(None)?;
let service_url = Url::parse("https://<storage_account_name>.queue.core.windows.net/")?;
let service_client = QueueServiceClient::new(service_url, Some(credential), None)?;
let queue_client = service_client.queue_client("<queue_name>")?;
let response = queue_client.receive_messages(None).await?;
let messages = response.into_model()?;
for msg in messages.items.unwrap_or_default() {
println!("{}", msg.message_text.as_deref().unwrap_or("<empty>"));
}
Ok(())
}§Next steps
§Provide feedback
If you encounter bugs or have suggestions, open an issue.
§Contributing
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.
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.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Re-exports§
pub use clients::QueueClient;pub use clients::QueueClientOptions;pub use clients::QueueServiceClient;pub use clients::QueueServiceClientOptions;