Skip to content

Instantly share code, notes, and snippets.

@rxaviers
Last active January 8, 2024 00:26
Show Gist options
  • Save rxaviers/623e8450d9234f86a29477e9373c081d to your computer and use it in GitHub Desktop.
Save rxaviers/623e8450d9234f86a29477e9373c081d to your computer and use it in GitHub Desktop.
Eugenio (logicalis) streaming

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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment