Stream and Ingest Data with Azure Event Hubs
TypeScript SDK for Azure Event Hubs - produce, consume, checkpoint, and replay high-throughput event streams.
Why it matters
Leverage Azure Event Hubs SDK for TypeScript to build high-throughput event streaming and real-time data ingestion pipelines. This asset facilitates sending and receiving events, managing checkpoints, and integrating with Azure services.
Outcomes
What it gets done
Send events to Azure Event Hubs, with options for batching and specific partitions.
Receive events from Azure Event Hubs, supporting simple and checkpointed consumption.
Configure event processing with options for start position, batch size, and wait times.
Implement robust error handling and best practices for reliable event streaming.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-azure-eventhub-ts | bash Overview
Azure Event Hubs SDK for TypeScript
A TypeScript SDK reference for Azure Event Hubs covering event production, batching, partition-aware consumption, checkpointing, and replay from a specific position. Use when building a TypeScript service that produces or consumes high-throughput event streams on Azure Event Hubs with durable checkpointing.
What it does
This skill covers @azure/event-hubs, the TypeScript SDK for Azure Event Hubs, Azure's high-throughput event-streaming service. An EventHubProducerClient batches and sends events (createBatch(), batch.tryAdd({ body }), sendBatch()), optionally pinned to a specific partitionId or hashed consistently by partitionKey for ordering. An EventHubConsumerClient, scoped to a consumer group like "$Default", subscribes with processEvents/processError handlers; for production use it pairs with a BlobCheckpointStore (backed by Azure Blob Storage) so processing position survives restarts, calling context.updateCheckpoint() after each processed batch.
When to use - and when NOT to
Use this skill when ingesting or emitting real-time event streams at scale - IoT telemetry, application events, or log/metric pipelines - from a TypeScript service. It is specifically for Event Hubs' publish/subscribe streaming model with partitions and checkpoints; it is not a general message-queue client (no per-message dead-lettering or FIFO queue semantics of, say, Service Bus) and consumers should not checkpoint after a processing failure, since that would silently drop the unprocessed events - the SDK relies on re-delivery from the last checkpoint for at-least-once processing.
Inputs and outputs
Sends take structured events (body, optional properties, contentType, correlationId) grouped into a batch. Consumption yields ReceivedEventData objects per partition, exposing properties, sequenceNumber, enqueuedTimeUtc, and offset, delivered through a PartitionContext that also exposes updateCheckpoint. startPosition controls where a subscription begins reading per partition: "@earliest", "@latest" (new events only), a specific numeric offset, or an enqueuedOn timestamp. getEventHubProperties() returns the hub's partition IDs, and getPartitionProperties(id) returns lastEnqueuedSequenceNumber for lag monitoring against what a consumer has actually processed.
npm install @azure/event-hubs @azure/identity
npm install @azure/eventhubs-checkpointstore-blob @azure/storage-blob
Integrations
Authenticates via DefaultAzureCredential from @azure/identity. Checkpointing integrates with @azure/storage-blob through BlobCheckpointStore, storing consumer progress per partition per consumer group in a blob container. maxBatchSize/maxWaitTimeInSeconds options on subscribe() control how events are grouped into processEvents calls. The processError handler distinguishes transient MessagingErrors, which the SDK automatically retries, from fatal errors that need explicit handling - a distinction worth checking before deciding whether an error needs to bubble up to alerting or can be logged and left to the SDK's own retry logic.
Who it's for
TypeScript developers building real-time ingestion or streaming pipelines on Azure - IoT telemetry collectors, event-driven microservices, or analytics pipelines needing exactly-once-style processing guarantees. The skill's best practices push toward always checkpointing in production, batching sends, using partition keys to keep related events ordered, running separate consumer groups per downstream pipeline, closing producer/consumer clients when done, and actively monitoring consumer lag against lastEnqueuedSequenceNumber.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.