CompletableFuture<String> queryChangeFeedAsync(CosmosChangeFeedRequestOptions cosmosChangeFeedRequestOptions,
      List<CloudBlobMetadata> changeFeed, Timer timer) {

    CompletableFuture<String> resultFuture = new CompletableFuture<>();
    azureMetrics.changeFeedQueryCount.inc();
    Timer.Context operationTime = timer.time();

    // Since the requestCharge is being used inside lambda expression below, it needs to be atomic.
    AtomicReference<String> continuationToken = new AtomicReference<>();

    // Query change feed
    CosmosPagedFlux<CloudBlobMetadata> pagedFluxResponse =
        cosmosAsyncContainer.queryChangeFeed(cosmosChangeFeedRequestOptions, CloudBlobMetadata.class);

    // Read the pages containing the cosmos change feed asynchronously and update the continuation token as we are reading.
    pagedFluxResponse.byPage().subscribe(fluxResponse -> {
      logger.debug("Got a page of query result with " + fluxResponse.getResults().size() + " items(s)"
          + " and request charge of " + fluxResponse.getRequestCharge());
      changeFeed.addAll(fluxResponse.getResults());
      continuationToken.set(fluxResponse.getContinuationToken());
    }, throwable -> {
      azureMetrics.changeFeedQueryFailureCount.inc();
      resultFuture.completeExceptionally(throwable);
      operationTime.stop();
    }, () -> {
      operationTime.stop();
      resultFuture.complete(continuationToken.get());
    });

    return resultFuture;
  }
Query Cosmos change feed to get the next set of {@code CloudBlobMetadata} objects asynchronously.
@param cosmosChangeFeedRequestOptions {@link CosmosChangeFeedRequestOptions} containing the options for the change feed request.
@param changeFeed {@link CloudBlobMetadata} {@code List} to be populated with the next set of entries returned by change feed query.
@param timer the {@link Timer} to use to record query time (excluding waiting).
@return a {@link CompletableFuture} that will eventually contain next continuation token or {@link CosmosException}
        in case of any error.
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/CosmosDataAccessor.java