ChangeFeedProcessorBuilder Class

Definition

Provides a flexible way to to create an instance of IChangeFeedProcessor with custom set of parameters.

public class ChangeFeedProcessorBuilder
type ChangeFeedProcessorBuilder = class
Public Class ChangeFeedProcessorBuilder
Inheritance
System.Object
ChangeFeedProcessorBuilder

Examples

// Observer.cs
namespace Sample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.Azure.Documents;
    using Microsoft.Azure.Documents.ChangeFeedProcessor.FeedProcessing;

    class SampleObserver : IChangeFeedObserver
    {
        public Task CloseAsync(IChangeFeedObserverContext context, ChangeFeedObserverCloseReason reason)
        {
            return Task.CompletedTask;  // Note: requires targeting .Net 4.6+.
        }

        public Task OpenAsync(IChangeFeedObserverContext context)
        {
            return Task.CompletedTask;
        }

        public Task ProcessChangesAsync(IChangeFeedObserverContext context, IReadOnlyList<Document> docs, CancellationToken cancellationToken)
        {
            Console.WriteLine("ProcessChangesAsync: partition {0}, {1} docs", context.PartitionKeyRangeId, docs.Count);
            return Task.CompletedTask;
        }
    }
}

// Main.cs
namespace Sample
{
    using System;
    using System.Threading.Tasks;
    using Microsoft.Azure.Documents.ChangeFeedProcessor;
    using Microsoft.Azure.Documents.ChangeFeedProcessor.Logging;

    class ChangeFeedProcessorSample
    {
        public static void Run()
        {
            RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo()
            {
                DatabaseName = "DatabaseName",
                CollectionName = "MonitoredCollectionName",
                Uri = new Uri("https://sampleservice.documents.azure.com:443/"),
                MasterKey = "-- the auth key"
            };

            DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo()
            {
                DatabaseName = "DatabaseName",
                CollectionName = "leases",
                Uri = new Uri("https://sampleservice.documents.azure.com:443/"),
                MasterKey = "-- the auth key"
            };

            var builder = new ChangeFeedProcessorBuilder();
            var processor = await builder
                .WithHostName("SampleHost")
                .WithFeedCollection(feedCollectionInfo)
                .WithLeaseCollection(leaseCollectionInfo)
                .WithObserver<SampleObserver>()
                .BuildAsync();

            await processor.StartAsync();

            Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop...");
            Console.ReadLine();

            await processor.StopAsync();
        }
    }
}

Constructors

ChangeFeedProcessorBuilder()

Methods

BuildAsync()

Builds a new instance of the IChangeFeedProcessor with the specified configuration.

BuildEstimatorAsync()

Builds a new instance of the IRemainingWorkEstimator to estimate pending work with the specified configuration.

WithCheckpointPartitionProcessorFactory(ICheckpointPartitionProcessorFactory)

Sets the ICheckpointPartitionProcessorFactory to be used to create IPartitionProcessor for partition processing.

WithCollectionResourceId(String)

Sets the Collection Resource Id of the monitored collection.

WithDatabaseResourceId(String)

Sets the Database Resource Id of the monitored collection.

WithFeedCollection(DocumentCollectionInfo)

Sets the DocumentCollectionInfo of the collection to listen for changes.

WithFeedDocumentClient(DocumentClient)

Sets an existing DocumentClient to be used to read from the monitored collection.

WithFeedDocumentClient(IChangeFeedDocumentClient)

Sets an existing IChangeFeedDocumentClient to be used to read from the monitored collection.

WithHealthMonitor(IHealthMonitor)

Sets the IHealthMonitor to be used to monitor unhealthiness situation.

WithHostName(String)

Sets the Host name.

WithLeaseCollection(DocumentCollectionInfo)

Sets the DocumentCollectionInfo of the collection to use for leases.

WithLeaseDocumentClient(DocumentClient)

Sets an existing DocumentClient to be used to read from the leases collection.

WithLeaseDocumentClient(IChangeFeedDocumentClient)

Sets an existing IChangeFeedDocumentClient to be used to read from the leases collection.

WithLeaseStoreManager(ILeaseStoreManager)

Sets the ILeaseStoreManager to be used to manage leases.

WithObserver<T>()

Sets an existing IChangeFeedObserver type to be used by a IChangeFeedObserverFactory to process changes.

WithObserverFactory(IChangeFeedObserverFactory)

Sets the IChangeFeedObserverFactory to be used to generate IChangeFeedObserver

WithPartitionLoadBalancingStrategy(IParitionLoadBalancingStrategy)

Sets the IParitionLoadBalancingStrategy to be used for partition load balancing

WithPartitionProcessorFactory(IPartitionProcessorFactory)

Sets the IPartitionProcessorFactory to be used to create IPartitionProcessor for partition processing.

WithProcessorOptions(ChangeFeedProcessorOptions)

Sets the ChangeFeedProcessorOptions to be used by this instance of IChangeFeedProcessor.

Applies to