Install npm modules below
npm install @azure/event-hubs@5.0.0-preview.2
Use Node.js >=10 and run the below where Eugenio.getDatastreamInfo is https://portal.stg.eugenio.io/api/v1/apis/datastream?swagger-ui#/Data%20Stream/get_datastream
const { EventHubClient, EventPosition } = require("@azure/event-hubs");
async function main() {
const { namespace, eventHubName, sasKeyName, sasKey, consumerGroupName } = await Eugenio.getDatastreamInfo();
const client = new EventHubClient(
`Endpoint=sb://${namespace}.servicebus.windows.net/;SharedAccessKeyName=${sasKeyName};SharedAccessKey=${sasKey}`,
eventHubName
);
const partitionIds = await client.getPartitionIds();
const consumer = client.createConsumer(
consumerGroupName[0],
partitionIds[0],
EventPosition.earliest()
);
try {
for await (const events of consumer.getEventIterator()) {
console.log("Received event: %o", events.body);
}
await consumer.close();
} finally {
await client.close();
}
}
main().catch(error => console.warn(error));