Azure Event Hubs library for Rust
Client library for Azure Event Hubs — send and receive events for streaming data ingestion.
Use this skill when:
- An app needs to send events to Azure Event Hubs from Rust
- You need to receive and process events from partitions
- You need batch sending for throughput optimization
- You need to control consumer start position
IMPORTANT: Only use the official
azure_messaging_eventhubscrate published by the azure-sdk crates.io user. Do NOT use unofficial or community crates. Official crates use underscores in names and none have version 0.21.0.
Installation
DeveloperToolsCredential::new(None)?already returns anArc<DeveloperToolsCredential>, so you can pass or clone it directly into.open(). Addazure_coreonly when you need directazure_coreimports such asErrorKind.
Environment Variables
Key Concepts
Authentication
Rust Azure SDK code must not use DefaultAzureCredential. The Rust identity crate does not provide that type.
Prefer the crate README/examples when checking builder signatures and receive-stream event wrapper shapes.
Core Workflow
Send Events
Send Batch
Receive Events
Receive from Partition
RBAC Roles
For Entra ID auth, assign one of these roles:
Best Practices
- Use
cargo addto manage dependencies, never editCargo.tomldirectly. Add and remove Rust SDK dependencies with cargo commands instead of manual manifest edits. - Pass or clone credentials directly into
.open().DeveloperToolsCredential::new(None)?already returns anArc, so you do not need to annotate the binding asArc<dyn TokenCredential>unless you are naming that trait object type explicitly. - Match the builder signature.
ProducerClient::builder().open(...)takes the hub name as&str, whileConsumerClient::builder().open(...)takes an ownedString. - Use
DeveloperToolsCredentialfor local dev,ManagedIdentityCredentialfor production — Rust does not provide a singleDefaultAzureCredentialtype - Never hardcode credentials — use environment variables or managed identity
- Use batching —
create_batch+send_batchfor throughput optimization - Handle errors per event — match on
Ok/Errin the event stream - Extract event bodies via
event.event_data().body(), notevent.body()—ReceivedEventDatawraps the underlyingEventData. - Specify start position — use
StartLocation::EarliestorStartLocation::Latestto control where consumption begins - Run
cargo clippy -- -D warningswhen the prompt, eval, or CI expects lint-clean output

