azure-eventhub-dotnet – DevOps & Infrastructure skill for AI agents
Azure Event Hubs SDK for .NET.
Install the azure-eventhub-dotnet skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventhub-dotnet-93dbf.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /azure-eventhub-dotnet – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventhub-dotnet-93dbf.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $azure-eventhub-dotnet – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventhub-dotnet-93dbf.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /azure-eventhub-dotnet – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventhub-dotnet-93dbf.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /azure-eventhub-dotnet – then describe the task you want done.
SKILL.md content
Azure.Messaging.EventHubs (.NET)
High-throughput event streaming SDK for sending and receiving events via Azure Event Hubs.
Installation
# Core package (sending and simple receiving)
dotnet add package Azure.Messaging.EventHubs
# Processor package (production receiving with checkpointing)
dotnet add package Azure.Messaging.EventHubs.Processor
# Authentication
dotnet add package Azure.Identity
# For checkpointing (required by EventProcessorClient)
dotnet add package Azure.Storage.BlobsCurrent Versions: Azure.Messaging.EventHubs v5.12.2, Azure.Messaging.EventHubs.Processor v5.12.2
Environment Variables
EVENTHUB_FULLY_QUALIFIED_NAMESPACE=<namespace>.servicebus.windows.net
EVENTHUB_NAME=<event-hub-name>
# For checkpointing (EventProcessorClient)
BLOB_STORAGE_CONNECTION_STRING=<storage-connection-string>
BLOB_CONTAINER_NAME=<checkpoint-container>
# Alternative: Connection string auth (not recommended for production)
EVENTHUB_CONNECTION_STRING=Endpoint=sb://<namespace>.servicebus.windows.net/;SharedAccessKeyName=...Authentication
using Azure.Identity;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
// Always use DefaultAzureCredential for production
var credential = new DefaultAzureCredential();
var fullyQualifiedNamespace = Environment.GetEnvironmentVariable("EVENTHUB_FULLY_QUALIFIED_NAMESPACE");
var eventHubName = Environment.GetEnvironmentVariable("EVENTHUB_NAME");
var producer = new EventHubProducerClient(
fullyQualifiedNamespace,
eventHubName,
credential);Required RBAC Roles:
- Sending:
Azure Event Hubs Data Sender - Receiving:
Azure Event Hubs Data Receiver - Both:
Azure Event Hubs Data Owner
Delivery, checkpoint and shutdown limits
These are SDK fragments requiring verified installed versions and fixtures. Enqueueing a buffered event is not broker acknowledgement; handle success/failure and shutdown flush explicitly. Receiving is at-least-once: perform durable idempotent processing before partition-local checkpoints, never use the shared counter below across concurrent partitions as a correctness boundary. Check for an actual event before dereferencing empty reads. Wrap processing lifetime in try/finally so cancellation still calls StopProcessingAsync; keep event bodies/errors private. Sender plus Receiver roles can be combined without granting Data Owner. Select credential/tenant deliberately and scope creation/sending/receiving/checkpoint storage authority.
Client Types
| Client | Purpose | When to Use |
|--------|---------|-------------|
| EventHubProducerClient | Send events immediately in batches | Real-time sending, full control over batching |
| EventHubBufferedProducerClient | Automatic batching with background sending | High-volume, fire-and-forget scenarios |
| EventHubConsumerClient | Simple event reading | Prototyping only, NOT for production |
| EventProcessorClient | Production event processing | Always use this for receiving in production |
Core Workflow
1. Send Events (Batch)
using Azure.Identity;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
await using var producer = new EventHubProducerClient(
fullyQualifiedNamespace,
eventHubName,
new DefaultAzureCredential());
// Create a batch (respects size limits automatically)
EventDataBatch batch = await producer.CreateBatchAsync();
// Add events to batch
var events = new[]
{
new EventData(BinaryData.FromString("{\"id\": 1, \"message\": \"Hello\"}")),
new EventData(BinaryData.FromString("{\"id\": 2, \"message\": \"World\"}"))
};
foreach (var eventData in events)
{
if (!batch.TryAdd(eventData))
{
// Batch is full - send it and create a new one
await producer.SendAsync(batch);
batch.Dispose();
batch = await producer.CreateBatchAsync();
if (!batch.TryAdd(eventData))
{
throw new Exception("Event too large for empty batch");
}
}
}
// Send remaining events; production code wraps the whole loop in try/finally
// so the current batch is disposed on every exception path.
if (batch.Count > 0)
{
await producer.SendAsync(batch);
}
batch.Dispose();2. Send Events (Buffered - High Volume)
using Azure.Messaging.EventHubs.Producer;
var options = new EventHubBufferedProducerClientOptions
{
MaximumWaitTime = TimeSpan.FromSeconds(1)
};
await using var producer = new EventHubBufferedProducerClient(
fullyQualifiedNamespace,
eventHubName,
new DefaultAzureCredential(),
options);
// Handle send success/failure
producer.SendEventBatchSucceededAsync += args =>
{
Console.WriteLine($"Batch sent: {args.EventBatch.Count} events");
return Task.CompletedTask;
};
producer.SendEventBatchFailedAsync += args =>
{
Console.WriteLine($"Batch failed: {args.Exception.Message}");
return Task.CompletedTask;
};
// Enqueue events (sent automatically in background)
for (int i = 0; i < 1000; i++)
{
await producer.EnqueueEventAsync(new EventData($"Event {i}"));
}
// Flush remaining events before disposing
await producer.FlushAsync();3. Receive Events (Production - EventProcessorClient)
using Azure.Identity;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Consumer;
using Azure.Messaging.EventHubs.Processor;
using Azure.Storage.Blobs;
// Blob container for checkpointing
var blobClient = new BlobContainerClient(
Environment.GetEnvironmentVariable("BLOB_STORAGE_CONNECTION_STRING"),
Environment.GetEnvironmentVariable("BLOB_CONTAINER_NAME"));
await blobClient.CreateIfNotExistsAsync();
// Create processor
var processor = new EventProcessorClient(
blobClient,
EventHubConsumerClient.DefaultConsumerGroup,
fullyQualifiedNamespace,
eventHubName,
new DefaultAzureCredential());
// Handle events
processor.ProcessEventAsync += async args =>
{
Console.WriteLine($"Partition: {args.Partition.PartitionId}");
Console.WriteLine($"Data: {args.Data.EventBody}");
// Checkpoint after processing (or batch checkpoints)
await args.UpdateCheckpointAsync();
};
// Handle errors
processor.ProcessErrorAsync += args =>
{
Console.WriteLine($"Error: {args.Exception.Message}");
Console.WriteLine($"Partition: {args.PartitionId}");
return Task.CompletedTask;
};
// Start processing
await processor.StartProcessingAsync();
// Run until cancelled
await Task.Delay(Timeout.Infinite, cancellationToken);
// Stop gracefully
await processor.StopProcessingAsync();4. Partition Operations
// Get partition IDs
string[] partitionIds = await producer.GetPartitionIdsAsync();
// Send to specific partition (use sparingly)
var options = new SendEventOptions
{
PartitionId = "0"
};
await producer.SendAsync(events, options);
// Use partition key (recommended for ordering)
var batchOptions = new CreateBatchOptions
{
PartitionKey = "customer-123" // Events with same key go to same partition
};
using var batch = await producer.CreateBatchAsync(batchOptions);EventPosition Options
Control where to start reading:
// Start from beginning
EventPosition.Earliest
// Start from end (new events only)
EventPosition.Latest
// Start from specific offset
EventPosition.FromOffset(12345)
// Start from specific sequence number
EventPosition.FromSequenceNumber(100)
// Start from specific time
EventPosition.FromEnqueuedTime(DateTimeOffset.UtcNow.AddHours(-1))ASP.NET Core Integration
// Program.cs
using Azure.Identity;
using Azure.Messaging.EventHubs.Producer;
using Microsoft.Extensions.Azure;
builder.Services.AddAzureClients(clientBuilder =>
{
clientBuilder.AddEventHubProducerClient(
builder.Configuration["EventHub:FullyQualifiedNamespace"],
builder.Configuration["EventHub:Name"]);
clientBuilder.UseCredential(new DefaultAzureCredential());
});
// Inject in controller/service
public class EventService
{
private readonly EventHubProducerClient _producer;
public EventService(EventHubProducerClient producer)
{
_producer = producer;
}
public async Task SendAsync(string message)
{
using var batch = await _producer.CreateBatchAsync();
if (!batch.TryAdd(new EventData(message)))
throw new ArgumentException("Message exceeds the empty batch limit", nameof(message));
await _producer.SendAsync(batch);
}
}Best Practices
1. Use EventProcessorClient for receiving — Never use EventHubConsumerClient in production
2. Checkpoint strategically — After N events or time interval, not every event
3. Use partition keys — For ordering guarantees within a partition
4. Reuse clients — Create once, use as singleton (thread-safe)
5. Use await using — Ensures proper disposal
6. Handle ProcessErrorAsync — Always reg
… (full content is in the download package)
Related skills
- azure-eventhub-py – Azure Event Hubs SDK for Python streaming. Use for high-throughput event ingestion…
- azure-eventhub-ts – High-throughput event streaming and real-time data ingestion.
- azure-functions – Expert patterns for Azure Functions development including isolated worker model, Durable…
- azure-functions-devsec – Build serverless applications on Azure Functions. Configure triggers, bindings, and…
- azure-identity-dotnet – Azure Identity SDK for .NET. Authentication library for Azure SDK clients using…
- azure-identity-java – Authenticate Java applications with Azure services using Microsoft Entra ID (Azure AD).
- azure-identity-py – Azure Identity SDK for Python authentication. Use for DefaultAzureCredential, managed…
- hermes-s6-container-supervision – Modify or debug s6 services in the Hermes Docker image.