|sendEvents.js||demonstrates how the send() function can be used to send events to Event Hubs|
|useWithIotHub.js||demonstrates how to use the
|websockets.js||demonstrates how to use WebSockets enable Event Hubs to work over an HTTP proxy and in environments where the standard AMQP port 5671 is blocked (see the sample for more information)|
|usingAadAuth.js||demonstrates how to instantiate EventHubsClient using AAD token credentials obtained from using Service Principal Secrets|
|receiveEvents.js||demonstrates how to use the EventHubConsumerClient to process events from all partitions of a consumer group in an Event Hubs instance.|
EventHubConsumerClient supports checkpointing using the
@azure/storage-blob packages. For an example that demonstrates how to use this functionality, see the receiveEventsUsingCheckpointStore sample in the
The samples are compatible with Node.js >= 8.0.0.
You need an Azure subscription and an Azure Event Hub resource to run these sample programs. The IOT Hub sample additionally requires an IOT Hub resource. Samples retrieve credentials to access the event hub 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 requires some additional consideration. For details, please see the package README.
To run the samples using the published version of the package:
- Install the dependencies using
- 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 from
.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):
Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform):
npx cross-env EVENTHUB_NAME="<hub name>" EVENTHUB_CONNECTION_STRING="<connection string>" node dist/sendEvents.js
Take a look at our API Documentation for more information about the APIs that are available in the clients.