private static async Task ReadFeedJson <TEventHandler>(Container container, TEventHandler eventHandler, int pageSizeHint, string?continuationToken, JsonSerializerOptions options, CancellationToken cancellationToken) where TEventHandler : IJsonEventFeedHandler { var requestOptions = new ChangeFeedRequestOptions { PageSizeHint = pageSizeHint }; FeedIterator iterator = container.GetChangeFeedStreamIterator( continuationToken is null ? ChangeFeedStartFrom.Beginning() : ChangeFeedStartFrom.ContinuationToken(continuationToken), ChangeFeedMode.Incremental, requestOptions); while (iterator.HasMoreResults && !cancellationToken.IsCancellationRequested) { using ResponseMessage response = await iterator.ReadNextAsync(cancellationToken).ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { break; } response.EnsureSuccessStatusCode(); CosmosEventStore <TContainerFactory, TSnapshotReader> .ProcessEventFeedStream(eventHandler, response.Content, options.DefaultBufferSize, cancellationToken); await eventHandler.HandleBatchComplete(response.ContinuationToken).ConfigureAwait(false); } }
private static Task ReadFeed(Container container, IEventFeedHandler eventHandler, int pageSizeHint, string?continuationToken, JsonSerializerOptions options, CancellationToken cancallationToken) { return(CosmosEventStore <TContainerFactory, TSnapshotReader> .ReadFeedJson(container, new JsonEventFeed.JsonEventFeedHandlerOverJsonSerializer(eventHandler, options), pageSizeHint, continuationToken, options, cancallationToken)); }
/// <summary> /// Reads an aggregate root. /// </summary> /// <typeparam name="TEventHandler">The type of the event reader for the aggregate root. This is an <see cref="IJsonEventFeedHandler"/>.</typeparam> /// <param name="eventHandler">The event reader capable of decoding and applying the event payloads for this aggregate root.</param> /// <param name="pageSizeHint">A hint as to the number of items you get in a page of results.</param> /// <param name="continuationToken">The (optional) continuation token to resume the feed from a particular point.</param> /// <param name="cancellationToken">The cancellation token to terminate reading the feed.</param> /// <returns>A <see cref="Task{TResult}"/> which completes when the feed terminates.</returns> public Task ReadFeedJson <TEventHandler>(TEventHandler eventHandler, int pageSizeHint, string?continuationToken, CancellationToken cancellationToken) where TEventHandler : IJsonEventFeedHandler { return(CosmosEventStore <TContainerFactory, TSnapshotReader> .ReadFeedJson(this.ContainerFactory.GetContainer(), eventHandler, pageSizeHint, continuationToken, this.Options, cancellationToken)); }