How to use the @azure/event-hubs.EventPosition.earliest function in @azure/event-hubs

To help you get started, we’ve selected a few @azure/event-hubs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / receiveEventsStreaming.ts View on Github external
const consumerGroupName = "$Default";

  const onReceivedEventsHandler: OnReceivedEvents = async (events, context) => {
    for (const message of events) {
      console.log(`Received event: ${message.body}`);
    }
  };

  const subscription = client.subscribe(consumerGroupName, onReceivedEventsHandler,
    // for simplicity we'll just target a single partition for our demo
    partitionIds[0], {
    onError: async (err: Error, partitionContext: PartitionContext) => {
      console.log(`Error occurred in the subscription for ${partitionContext.partitionId}: ${err}`);
    },
    // if this subscription happens tob e the first
    defaultEventPosition: EventPosition.earliest()
  });

  // Waiting long enough before closing the consumer to receive event
  await delay(5000);
  await subscription.close();
  await client.close();
}
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / receiveEventsStreaming.ts View on Github external
async function main(): Promise {
  const client = new EventHubClient(connectionString, eventHubName);
  const partitionIds = await client.getPartitionIds();
  const consumer = client.createConsumer("$Default", partitionIds[0], EventPosition.earliest());

  const onMessageHandler: OnMessage = (brokeredMessage: EventData) => {
    console.log(`Received event: ${brokeredMessage.body}`);
  };
  const onErrorHandler: OnError = (err: MessagingError | Error) => {
    console.log("Error occurred: ", err);
  };

  try {
    const rcvHandler = consumer.receive(onMessageHandler, onErrorHandler);

    // Waiting long enough before closing the consumer to receive event
    await delay(5000);
    await rcvHandler.stop();
  } finally {
    await client.close();
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / receiveEventsLoop.ts View on Github external
async function main(): Promise {
  const client = new EventHubClient(connectionString, eventHubName);
  const partitionIds = await client.getPartitionIds();
  const consumer = client.createConsumer("$Default", partitionIds[0], EventPosition.earliest());
  const batchSize = 1;

  try {
    for (let i = 0; i < 5; i++) {
      const events = await consumer.receiveBatch(batchSize, 5);
      if (!events.length) {
        console.log("No more events to receive");
        break;
      }
      console.log(`Received events: ${events.map(event => event.body)}`);
    }

    let iteratorCount = 0;
    for await (const events of consumer.getEventIterator()) {
      iteratorCount++;
      console.log(`Received event: ${events.body}`);