Azure Event Hubs - Checkpoint Store client library samples for TypeScript
These sample programs show how to use the TypeScript client libraries for Azure Event Hubs - Checkpoint Store in some common scenarios.
File Name | Description |
---|---|
receiveEventsUsingCheckpointStore.ts | Demonstrates how to use the EventHubConsumerClient to process events from all partitions of a consumer group in an Event Hubs instance, as well as checkpointing along the way. Checkpointing using a durable store allows your application to be more resilient. When you restart your application after a crash (or an intentional stop), your application can continue consuming events from where it last checkpointed. |
receiveEventsWithApiSpecificStorage.ts | Demonstrates how to use the EventHubConsumerClient to process events from all partitions of a consumer group in an Event Hubs instance, as well as checkpointing along the way. This sample uses the createCustomPipeline function to override the targetted version of the Storage service. Checkpointing using a durable store allows your application to be more resilient. When you restart your application after a crash (or an intentional stop), your application can continue consuming events from where it last checkpointed. |
Prerequisites
The sample programs are compatible with Node.js >=12.0.0.
Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the TypeScript documentation. Install the TypeScript compiler using:
npm install -g typescript
You need an Azure subscription and the following Azure resources to run these sample programs:
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
Adapting the samples to run in the browser may require some additional consideration. For details, please see the package README.
Setup
To run the samples using the published version of the package:
- Install the dependencies using
npm
:
npm install
- Compile the samples:
npm run build
Edit the file
sample.env
, adding the correct credentials to access the Azure service and run the samples. Then rename the file fromsample.env
to just.env
. The sample programs will read this file automatically.Run whichever samples you like (note that some samples may require additional setup, see the table above):
node dist/receiveEventsUsingCheckpointStore.js
Alternatively, run a single sample with the correct environment variables set (setting up the .env
file is not required if you do this), for example (cross-platform):
npx cross-env EVENT_HUB_CONNECTION_STRING="<event hub connection string>" EVENT_HUB_NAME="<event hub name>" EVENT_HUB_CONSUMER_GROUP="<event hub consumer group>" STORAGE_CONTAINER_URL="<storage container url>" STORAGE_ACCOUNT_NAME="<storage account name>" STORAGE_ACCOUNT_KEY="<storage account key>" node dist/receiveEventsUsingCheckpointStore.js
Next Steps
Take a look at our API Documentation for more information about the APIs that are available in the clients.