public async Task StartListeningAsync(int maxBatchSize, TimeSpan waitTimeout, CancellationToken cancellationToken) { var readOptions = new ReadEventOptions { MaximumWaitTime = waitTimeout, }; await using var client = new EventHubConsumerClient(consumerGroup: "$default", connectionString: connectionString); await foreach (var receivedEvent in client.ReadEventsAsync(startReadingAtEarliestEvent:false, readOptions, cancellationToken)) { if (receivedEvent.Data == null) { // timeout. Yield and try again. await Task.Yield(); continue; } await ProcessAsync(Encoding.UTF8.GetString(receivedEvent.Data.Body.ToArray()), cancellationToken); } }