How to use the @azure/event-hubs.EventHubConsumerClient 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
async function main(): Promise {
  const client = new EventHubConsumerClient(connectionString, eventHubName);
  const partitionIds = await client.getPartitionIds();
  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
github Azure / azure-sdk-for-js / sdk / eventhub / eventhubs-checkpointstore-eventProcessor.ts View on Github external
async function main() {
  const consumerClient = new EventHubConsumerClient(connectionString, eventHubName);
  const containerClient = new ContainerClient(storageConnectionString, containerName);
  await containerClient.create();

  const processEvents = async (events: ReceivedEventData[], context: PartitionContext & PartitionCheckpointer) => {
    // events can be empty if no events were recevied in the last 60 seconds.
    // This interval can be configured when creating the EventProcessor
    if (events.length === 0) {
      return;
    }

    for (const event of events) {
      console.log(
        `Received event: '${event.body}' from partition: '${context.partitionId}' and consumer group: '${context.consumerGroupName}'`
      );
    }
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / receiveEventsUsingCheckpointStore.ts View on Github external
export async function main() {
  console.log(`Running receiveEventsUsingCheckpointStore sample`);

  // this client will be used by our eventhubs-checkpointstore-blob, which 
  // persists any checkpoints from this session in Azure Storage
  const containerClient = new ContainerClient(storageConnectionString, containerName);

  if (!(await containerClient.exists())) {
    await containerClient.create();
  }

  const checkpointStore : CheckpointStore = new BlobCheckpointStore(containerClient);

  const consumerClient = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName, checkpointStore);
   
  const subscription = consumerClient.subscribe({
      processEvents: async (events, context) => {
        for (const event of events) {
          console.log(`Received event: '${event.body}' from partition: '${context.partitionId}' and consumer group: '${context.consumerGroup}'`);
        }
    
        try {
          // save a checkpoint for the last event now that we've processed this batch.
          await context.updateCheckpoint(events[events.length - 1]);
        } catch (err) {
          console.log(`Error when checkpointing on partition ${context.partitionId}: `, err);
          throw err;
        };

        console.log(
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / receiveEvents.ts View on Github external
export async function main() {
  console.log(`Running receiveEvents sample`);
  
  const consumerClient = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);

  const subscription = consumerClient.subscribe({
    // The callback where you add your code to process incoming events
    processEvents: async (events, context) => {
      for (const event of events) {
        console.log(
          `Received event: '${event.body}' from partition: '${context.partitionId}' and consumer group: '${context.consumerGroup}'`
        );
      }
    },
    processError: async (err, context) => {
      console.log(`Error : ${err}`);
    }
  });

  await cleanupAfterWaiting(async () => {
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / useWithIotHub.ts View on Github external
export async function main(): Promise {
  console.log(`Running useWithIotHub sample`);
  const client = new EventHubConsumerClient(consumerGroup, connectionString);
  /*
   Refer to other samples, and place your code here to receive events using the above client.
   Please note that send operations are not supported when this client is used against an IotHub instance
  */
  await client.close();
  console.log(`Exiting useWithIotHub sample`);
}
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / usingAadAuth.ts View on Github external
export async function main(): Promise {
  console.log(`Running usingAadAuth sample`);

  const credential = new DefaultAzureCredential();
  const client = new EventHubConsumerClient(consumerGroup, eventHubsFullyQualifiedName, eventHubName, credential);
  /*
   Refer to other samples, and place your code here
   to send/receive events
  */
  await client.close();

  console.log(`Exiting usingAadAuth sample`);
}
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / samples / websockets.ts View on Github external
export async function main(): Promise {
  console.log(`Running websockets sample`);

  const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName, {
    webSocketOptions: {
      webSocket: WebSocket,
      webSocketConstructorOptions: { agent: proxyAgent }
    }    
  });
  /*
   Refer to other samples, and place your code here to send/receive events
  */
  await client.close();

  console.log(`Exiting websockets sample`);
}
github sematext / logagent-js / lib / plugins / input / azure-event-hub.js View on Github external
function InputAzureEventhub (config, eventEmitter) {
  this.config = config
  this.eventEmitter = eventEmitter
  if (!this.config.bodyField) {
    this.config.bodyField = 'body'
  }
  if (!this.config.consumerGroup) {
    this.config.bodyField = '$Default'
  }
  this.client = new EventHubConsumerClient(this.config.consumerGroup || '$Default', config.endpoint, config.name)
}