Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)48k · #3930

azure-eventhub-rust

Skill này làm gì

Đoạn mã này cho phép chương trình viết bằng Rust gửi và nhận dữ liệu (sự kiện) từ dịch vụ Azure Event Hubs. Nó hữu ích để thu thập lượng lớn dữ liệu thời gian thực.

Khi nào nên dùng

  • ✓Khi bạn cần gửi nhiều dữ liệu cảm biến để phân tích.
  • ✓Khi bạn cần nhận thông điệp từ các hệ thống khác để xử lý.
  • ✓Khi bạn xây dựng hệ thống ghi lại hoạt động theo thời gian thực.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-eventhub-rust/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-eventhub-rust/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để gửi một thông điệp đơn giản đến Azure Event Hubs bằng Rust?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn tạo một “producer” để gửi sự kiện hoặc một “consumer” để nhận sự kiện. Đoạn mã kết nối với dịch vụ Azure và quản lý việc gửi hoặc nhận dữ liệu.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Azure Event Hubs SDK for Rust

Client library for Azure Event Hubs — big data streaming platform and event ingestion service.

The examples below require a reviewed compatible crate set and replacement of every resource placeholder. Do not use production data for demonstration writes.

Installation

cargo add azure_messaging_eventhubs@=0.16.0 azure_identity@=1.1.0-beta.1 azure_core@=1.2.0-beta.1

Environment Variables

export EVENTHUBS_HOST="<namespace>.servicebus.windows.net"
export EVENTHUB_NAME="<eventhub-name>"

Key Concepts

  • Namespace — container for Event Hubs
  • Event Hub — stream of events partitioned for parallel processing
  • Partition — ordered sequence of events
  • Producer — sends events to Event Hub
  • Consumer — receives events from partitions

Producer Client

Create Producer

use azure_identity::DeveloperToolsCredential;
use azure_messaging_eventhubs::ProducerClient;

let credential = DeveloperToolsCredential::new(None)?;
let producer = ProducerClient::builder()
    .open("<namespace>.servicebus.windows.net", "eventhub-name", credential.clone())
    .await?;

Send Single Event

producer.send_event(vec![1, 2, 3, 4], None).await?;

Send Batch

let batch = producer.create_batch(None).await?;
if !batch.try_add_event_data(b"event 1".to_vec(), None)? {
    return Err("Event does not fit in the batch".into());
}
if !batch.try_add_event_data(b"event 2".to_vec(), None)? {
    return Err("Send the existing batch and retry the remaining event in a new batch".into());
}

producer.send_batch(batch, None).await?;

Consumer Client

Create Consumer

use azure_messaging_eventhubs::ConsumerClient;

let credential = DeveloperToolsCredential::new(None)?;
let consumer = ConsumerClient::builder()
    .open("<namespace>.servicebus.windows.net", "eventhub-name", credential.clone())
    .await?;

Receive Events

// Open receiver for specific partition
use futures::StreamExt;
let receiver = consumer.open_receiver_on_partition("0".to_string(), None).await?;
let mut events = receiver.stream_events();
// Bound the receive loop and handle the no-event timeout without logging payloads.
for _ in 0..100 {
    match tokio::time::timeout(std::time::Duration::from_secs(10), events.next()).await {
        Ok(Some(Ok(event))) => { /* process the authorized event and checkpoint safely */ }
        Ok(Some(Err(error))) => return Err(error.into()),
        Ok(None) | Err(_) => break,
    }
}

Get Event Hub Properties

let properties = consumer.get_eventhub_properties(None).await?;
println!("Partitions: {:?}", properties.partition_ids);

Get Partition Properties

let partition_props = consumer.get_partition_properties("0", None).await?;
println!("Last sequence number: {}", partition_props.last_enqueued_sequence_number);

Best Practices

  1. Reuse clients — create once, send many events
  2. Use batches — more efficient than individual sends
  3. Check batch capacity — try_add_event_data returns false when full
  4. Process partitions in parallel — each partition can be consumed independently
  5. Use consumer groups — isolate different consuming applications
  6. Handle checkpointing — use azure_messaging_eventhubs_checkpointstore_blob for distributed consumers

Checkpoint Store (Optional)

For distributed consumers with checkpointing:

cargo add azure_messaging_eventhubs_checkpointstore_blob

Event Hubs 0.16 uses the Azure core beta line, so pair it with the published matching identity beta; do not mix credential traits from the stable core line.

The reviewed example set uses azure_messaging_eventhubs 0.16.0 and compatible Azure core/credential crates. Record and commit Cargo.lock; source/API review is not a compiler or live-service test.

Reference Links

Resource Link
API Reference https://docs.rs/azure_messaging_eventhubs
Source Code https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/eventhubs/azure_messaging_eventhubs
crates.io https://crates.io/crates/azure_messaging_eventhubs

When to Use

Use when a Rust application publishes individual/batched events or consumes a specific Event Hubs partition with an explicit consumer group and checkpoint policy.

Limitations

…

Câu hỏi thường gặp

“Namespace” hay “Event Hub” là gì?

Namespace giống như một thư mục chứa các Event Hub của bạn. Event Hub là một luồng dữ liệu, trong đó các sự kiện được sắp xếp thành các phân vùng (partition).

“Producer” và “consumer” là gì?

Producer là bên gửi sự kiện vào Event Hub. Consumer là bên đọc sự kiện từ một phân vùng cụ thể.

Tôi có thể gửi nhiều sự kiện cùng một lúc không?

Có. Bạn có thể gom nhiều sự kiện thành một “batch” (lô) để gửi hiệu quả hơn.

Chi tiết

Mô tả gốc của tác giả

Azure Event Hubs SDK for Rust. Use for sending and receiving events, streaming data ingestion.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#3930
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự