// <Delegate>
        /// <summary>
        /// The delegate receives batches of changes as they are generated in the change feed and can process them.
        /// </summary>
        static async Task HandleChangesAsync(
            ChangeFeedProcessorContext context,
            IReadOnlyCollection <ToDoItem> changes,
            CancellationToken cancellationToken)
        {
            Console.WriteLine($"Started handling changes for lease {context.LeaseToken}...");
            Console.WriteLine($"Change Feed request consumed {context.Headers.RequestCharge} RU.");
            // SessionToken if needed to enforce Session consistency on another client instance
            Console.WriteLine($"SessionToken ${context.Headers.Session}");

            // We may want to track any operation's Diagnostics that took longer than some threshold
            if (context.Diagnostics.GetClientElapsedTime() > TimeSpan.FromSeconds(1))
            {
                Console.WriteLine($"Change Feed request took longer than expected. Diagnostics:" + context.Diagnostics.ToString());
            }

            foreach (ToDoItem item in changes)
            {
                Console.WriteLine($"Detected operation for item with id {item.id}, created at {item.creationTime}.");
                // Simulate some asynchronous operation
                await Task.Delay(10);
            }

            Console.WriteLine("Finished handling changes.");
        }
 private void ValidateContext(ChangeFeedProcessorContext changeFeedProcessorContext)
 {
     Assert.IsNotNull(changeFeedProcessorContext.LeaseToken);
     Assert.IsNotNull(changeFeedProcessorContext.Diagnostics);
     Assert.IsNotNull(changeFeedProcessorContext.Headers);
     Assert.IsNotNull(changeFeedProcessorContext.Headers.Session);
     Assert.IsTrue(changeFeedProcessorContext.Headers.RequestCharge > 0);
 }
예제 #3
0
        private void ValidateContext(ChangeFeedProcessorContext changeFeedProcessorContext)
        {
            Assert.IsNotNull(changeFeedProcessorContext.LeaseToken);
            Assert.IsNotNull(changeFeedProcessorContext.Diagnostics);
            Assert.IsNotNull(changeFeedProcessorContext.Headers);
            Assert.IsNotNull(changeFeedProcessorContext.Headers.Session);
            Assert.IsTrue(changeFeedProcessorContext.Headers.RequestCharge > 0);
            string diagnosticsAsString = changeFeedProcessorContext.Diagnostics.ToString();

            Assert.IsTrue(diagnosticsAsString.Contains("Change Feed Processor Read Next Async"));
        }
예제 #4
0
 async Task HandleChangeFeedStream(ChangeFeedProcessorContext context, Stream changes, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     var items = Serializer.DeserializeDocumentList <DbDoc>(changes);
     await BatchProcessor.HandleAsync(items, cancellationToken).ConfigureAwait(false);
 }