How to use the @azure/event-hubs.EventPosition.fromEnqueuedTime 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 nebrius / aquarium-control / server / src / messaging.ts View on Github external
client.receive(
    '1',
    (eventData) => { // on 'message
      if (eventData.annotations) {
        const enqueuedTime = eventData.annotations['x-opt-enqueued-time'];
        console.debug(`Received message from IoT Hub, enqueued at ${enqueuedTime}`);
      } else {
        console.debug(`Received message from IoT Hub`);
      }
      updateState(eventData.body);
    },
    (error) => {
      console.error(`Error receiving message from Event Hubs: ${error}`);
    },
    {
      eventPosition: EventPosition.fromEnqueuedTime(Date.now())
    }
  );
}
github Azure / azure-iot-explorer / src / server / serverBase.ts View on Github external
partitionIds.forEach(async (partitionId: string) => {
        const receiveOptions =  {
            consumerGroup,
            enableReceiverRuntimeMetric: true,
            eventPosition: EventPosition.fromEnqueuedTime(startTime),
            name: `${hubInfo.path}_${partitionId}`,
        };
        let receiver: ReceiveHandler;
        try {
            receiver = eventHubClient.receive(
                partitionId,
                onMessage,
                (err: object) => {
                    console.log(err); // tslint:disable-line: no-console
                },
                receiveOptions);
            receivers.push(receiver);
            await delay(SERVER_WAIT).then(() => {
                receiver.stop().catch(err => {
                    console.log(`couldn't stop receiver on partition[${partitionId}]: ${err}`); // tslint:disable-line: no-console
                });
github Azure / azure-sdk-for-js / common / smoke-test / EventHub.ts View on Github external
private static async SendAndReceiveEvents() {
    console.log("creating consumer...");

    const consumer = EventHubs.client.createConsumer(
      EventHubClient.defaultConsumerGroupName,
      EventHubs.partitionId[0],
      EventPosition.fromEnqueuedTime(new Date())
    );

    console.log("sending events...");
    const producerOptions = {
      partitionId: EventHubs.partitionId[0]
    };
    const producer = EventHubs.client.createProducer(producerOptions);
    await producer.send({ body: "JS Event Test 1" });
    await producer.send({ body: "JS Event Test 2" });
    await producer.send({ body: "JS Event Test 3" });

    console.log("receiving events...");
    let eventsReceived = await consumer.receiveBatch(3, 5);
    eventsReceived.forEach((event) => {
      console.log(`Event received: ${event.body}`);
    });
github Azure / azure-iot-sdk-node / ts-e2e / src / d2c.tests.ts View on Github external
partitionIds.forEach((partitionId) => {
            ehClient.receive(partitionId, onEventHubMessage, onEventHubError, { eventPosition: EventPosition.fromEnqueuedTime(startAfterTime) });
          });
          return new Promise((resolve) => setTimeout(() => resolve(), 3000));
github noopkat / electric-io / lib / liveHub.js View on Github external
function generateReceivers(options, partitionIds) {
  const { startTime, consumerGroup, receiveHandler, errorHandler } = options;

  const receiveOptions = {
    enqueuedTime: startTime,
    eventPosition: EventPosition.fromEnqueuedTime(startTime),
    consumerGroup: consumerGroup
  };

  return partitionIds.map(partitionId => {
    return ehClient.receive(
      partitionId,
      receiveHandler,
      errorHandler,
      receiveOptions
    );
  });
}
github microsoft / vscode-azure-iot-toolkit / src / iotHubMessageExplorer.ts View on Github external
partitionIds.forEach((partitionId) => {
                this.outputLine(label, `Created partition receiver [${partitionId}] for consumerGroup [${consumerGroup}]`);
                this._eventHubClient.receive(partitionId,
                    this.printMessage(this._outputChannel, label, deviceItem),
                    this.printError(this._outputChannel, label),
                    {
                        eventPosition: EventPosition.fromEnqueuedTime(startAfterTime),
                        consumerGroup,
                    });
            });
        }
github Azure-Samples / azure-iot-samples-node / iot-hub / Quickstarts / read-d2c-messages / ReadDeviceToCloudMessages.js View on Github external
return ids.map(function (id) {
    return ehClient.receive(id, printMessage, printError, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) });
  });
}).catch(printError);