ChangeFeedProcessorBuilder Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
-
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
Applies to
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Azure SDK for .NET