Skip to main content
skill

azure-eventhub-ts — Claude Code skill: what it does, how to install

Guides AI coding assistants on streaming events with Azure Event Hubs and TypeScript. Handy for ingesting IoT telemetry and processing partitioned real-time streams.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add microsoft/skills --skill azure-eventhub-ts -a claude-code
Open on GitHub

What azure-eventhub-ts does

The skill supplies TypeScript patterns for the @azure/event-hubs and @azure/identity SDKs. It directs the assistant to create EventHubProducerClient batches, route messages via partitionKey or partition IDs, and handle stream consumption.

For production subscribers, it covers persistent checkpointing using @azure/eventhubs-checkpointstore-blob alongside @azure/storage-blob. Without Azure Blob checkpointing, restarting a consumer resets stream progress. The guidance also notes that DefaultAzureCredential in production setups expects AZURE_TOKEN_CREDENTIALS or an explicit credential class.

What it helps with

  • send batched telemetry events routed by partition key
  • process streaming messages with persistent checkpoints in Blob Storage
  • configure Azure identity using managed credentials or default fallback
  • start event ingestion from specific offsets or timestamps

Example prompts for the agent

  • Write a TypeScript producer that sends batches to Event Hubs grouped by deviceId
  • Configure an EventHubConsumerClient subscription that checkpoints to Azure Blob Storage
  • Set up an Event Hub consumer reading from the @earliest offset

How to install azure-eventhub-ts

1Skills CLI (Vercel)

npx skills add microsoft/skills --skill azure-eventhub-ts -a claude-code

2Manually: put the files in place

~/.claude/skills/azure-eventhub-ts/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/azure-eventhub-ts/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about azure-eventhub-ts

How do I install azure-eventhub-ts in Claude Code?

Run npx skills add microsoft/skills --skill azure-eventhub-ts -a claude-code in your terminal. This downloads the skill to ~/.claude/skills/azure-eventhub-ts/SKILL.md.

What does azure-eventhub-ts do?

It provides reference code and architectural patterns for @azure/event-hubs in TypeScript. It helps write event producers, partitioned consumers, and checkpoint handlers.

What packages are required for checkpointing?

Checkpointing requires installing @azure/eventhubs-checkpointstore-blob and @azure/storage-blob. They store consumer offsets inside an Azure Blob container so restarts do not replay old events.

Source text

SKILL.md · MIT
---
name: azure-eventhub-ts
description: Build event streaming applications using Azure Event Hubs SDK for JavaScript (@azure/event-hubs). Use when implementing high-throughput event ingestion, real-time analytics, IoT telemetry, or event-driven architectures with partitioned consumers.
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: '@azure/event-hubs'
---

# Azure Event Hubs SDK for TypeScript

High-throughput event streaming and real-time data ingestion.

## Installation

```bash
npm install @azure/event-hubs @azure/identity
```

For checkpointing with consumer groups:
```bash
npm install @azure/eventhubs-checkpointstore-blob @azure/storage-blob
```

## Environment Variables

```bash
EVENTHUB_NAMESPACE=<namespace>.servicebus.windows.net
EVENTHUB_NAME=my-eventhub
STORAGE_ACCOUNT_NAME=<storage-account>
STORAGE_CONTAINER_NAME=checkpoints
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
```

## Authentication

```typescript
import { EventHubProducerClient, EventHubConsumerClient } from "@azure/event-hubs";
import { DefaultAzureCredential, ManagedIdentityCredential } from "@azure/identity";

const fullyQualifiedNamespace = process.env.EVENTHUB_NAMESPACE!;
const eventHubName = process.env.EVENTHUB_NAME!;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
const credential = new DefaultAzureCredential({requiredEnvVars: ["AZURE_TOKEN_CREDENTIALS"]});
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest#credential-classes
// const credential = new ManagedIdentityCredential();

// Producer
const producer = new EventHubProducerClient(fullyQualifiedNamespace, eventHubName, credential);

// Consumer
const consumer = new EventHubConsumerClient(
  "$Default", // Consumer group
  fullyQualifiedNamespace,
  eventHubName,
  credential
);
```

## Core Workflow

### Send Events

```typescript
const producer = new EventHubProducerClient(namespace, eventHubName, credential);

// Create batch and add events
const batch = await producer.createBatch();
batch.tryAdd({ body: { temperature: 72.5, deviceId: "sensor-1" } });
batch.tryAdd({ body: { temperature: 68.2, deviceId: "sensor-2" } });

await producer.sendBatch(batch);
await producer.close();
```

### Send to Specific Partition

```typescript
// By partition ID
const batch = await producer.createBatch({ partitionId: "0" });

// By partition key (consistent hashing)
const batch = await producer.createBatch({ partitionKey: "device-123" });
```

### Receive Events (Simple)

```typescript
const consumer = new EventHubConsumerClient("$Default", namespace, eventHubName, credential);

const subscription = consumer.subscribe({
  processEvents: async (events, context) => {
    for (const event of events) {
      console.log(`Partition: ${context.partitionId}, Body: ${JSON.stringify(event.body)}`);
    }
  },
  processError: async (err, context) => {
    console.error(`Error on partition ${context.partitionId}: ${err.message}`);
  },
});

// Stop after some time
setTimeout(async () => {
  await subscription.close();
  await consumer.close();
}, 60000);
```

### Receive with Checkpointing (Production)

```typescript
import { EventHubConsumerClient } from "@azure/event-hubs";
import { ContainerClient } from "@azure/storage-blob";
import { BlobCheckpointStore } from "@azure/eventhubs-checkpointstore-blob";

const containerClient = new ContainerClient(
  `https://${storageAccount}.blob.core.windows.net/${containerName}`,
  credential
);

const checkpointStore = new BlobCheckpointStore(containerClient);

const consumer = new EventHubConsumerClient(
  "$Default",
  namespace,
  eventHubName,
  credential,
  checkpointStore
);

const subscription = consumer.subscribe({
  processEvents: async (events, context) => {
    for (const event of events) {
      console.log(`Processing: ${JSON.stringify(event.body)}`);
    }
    // Checkpoint after processing batch
    if (events.length > 0) {
      await context.updateCheckpoint(events[events.length - 1]);
    }
  },
  processError: async (err, context) => {
    console.error(`Error: ${err.message}`);
  },
});
```

### Receive from Specific Position

```typescript
const subscription = consumer.subscribe({
  processEvents: async (events, context) => { /* ... */ },
  processError: async (err, context) => { /* ... */ },
}, {
  startPosition: {
    // Start from beginning
    "0": { offset: "@earliest" },
    // Start from end (new events only)
    "1": { offset: "@latest" },
    // Start from specific offset
    "2": { offset: "12345" },
    // Start from specific time
    "3": { enqueuedOn: new Date("2024-01-01") },
  },
});
```

## Event Hub Properties

```typescript
// Get hub info
const hubProperties = await producer.getEventHubProperties();
console.log(`Partitions: ${hubProperties.partitionIds}`);

// Get partition info
const partitionProperties = await producer.getPartitionProperties("0");
console.log(`Last sequence: ${partitionProperties.lastEnqueuedSequenceNumber}`);
```

## Batch Processing Options

```typescript
const subscription = consumer.subscribe(
  {
    processEvents: async (events, context) => { /* ... */ },
    processError: async (err, context) => { /* ... */ },
  },
  {
    maxBatchSize: 100,           // Max events per batch
    maxWaitTimeInSeconds: 30,    // Max wait for batch
  }
);
```

## Key Types

```typescript
import {
  EventHubProducerClient,
  EventHubConsumerClient,
  EventData,
  ReceivedEventData,
  PartitionContext,
  Subscription,
  SubscriptionEventHandlers,
  CreateBatchOptions,
  EventPosition,
} from "@azure/event-hubs";

import { BlobCheckpointStore } from "@azure/eventhubs-checkpointstore-blob";
```

## Event Properties

```typescript
// Send with properties
const batch = await producer.createBatch();
batch.tryAdd({
  body: { data: "payload" },
  properties: {
    eventType: "telemetry",
    deviceId: "sensor-1",
  },
  contentType: "application/json",
  correlationId: "request-123",
});

// Access in receiver
consumer.subscribe({
  processEvents: async (events, context) => {
    for (const event of events) {
      console.log(`Type: ${event.properties?.eventType}`);
      console.log(`Sequence: ${event.sequenceNumber}`);
      console.log(`Enqueued: ${event.enqueuedTimeUtc}`);
      console.log(`Offset: ${event.offset}`);
    }
  },
});
```

## Error Handling

```typescript
consumer.subscribe({
  processEvents: async (events, context) => {
    try {
      for (const event of events) {
        await processEvent(event);
      }
      await context.updateCheckpoint(events[events.length - 1]);
    } catch (error) {
      // Don't checkpoint on error - events will be reprocessed
      console.error("Processing failed:", error);
    }
  },
  processError: async (err, context) => {
    if (err.name === "MessagingError") {
      // Transient error - SDK will retry
      console.warn("Transient error:", err.message);
    } else {
      // Fatal error
      console.error("Fatal error:", err);
    }
  },
});
```

## Best Practices

1. **Use checkpointing** - Always checkpoint in production for exactly-once processing
2. **Batch sends** - Use `createBatch()` for efficient sending
3. **Partition keys** - Use partition keys to ensure ordering for related events
4. **Consumer groups** - Use separate consumer groups for different processing pipelines
5. **Handle errors gracefully** - Don't checkpoint on processing failures
6. **Close clients** - Always close producer/consumer when done
7. **Monitor lag** - Track `lastEnqueuedSequenceNumber` vs processed sequence

© Microsoft · MIT · microsoft/skills

Similar skills

All skills for Cloud: AWS, Azure, GCP →

From the same set242

The whole set →
azure-monitor-opentelemetry-ts This skill guides you through adding Azure Monitor and OpenTelemetry to Node.js apps for Application Insights traces, metrics, and logs. 1installs azure-keyvault-secrets-ts Teaches coding agents to manage secrets, encryption keys, and cryptographic operations in Azure Key Vault via official TypeScript SDKs. 1installs azure-keyvault-keys-ts This skill guides TypeScript work with Azure Key Vault keys, from creation and rotation to encryption and signing. Use it when building with the @azure/keyvault-keys SDK. 1installs azure-identity-ts A skill that walks the agent through Azure authentication with the @azure/identity library in TypeScript. Useful once DefaultAzureCredential or managed identity shows up in your code. 1installs azure-cosmos-ts A skill covering the Azure Cosmos DB JavaScript/TypeScript SDK: document CRUD, queries, bulk operations. Useful when the agent writes data-access code. 1installs azure-appconfiguration-ts A skill that gets your agent writing TypeScript against Azure App Configuration: settings, feature flags, Key Vault references and dynamic refresh. 1installs azure-ai-voicelive-ts Guides speech assistant development with the Azure AI Voice Live JavaScript and TypeScript SDK over bidirectional WebSockets. Useful for Node.js and browser real-time voice apps. 1installs azure-ai-translation-ts This skill helps build TypeScript apps with Azure translation SDKs for text and documents. Use it when adding language detection, transliteration, or batch document translation. 1installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor