/// <summary> /// /// </summary> /// <returns></returns> static async Task RunProcessingAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = Constants.CosmosDb_DatabaseName, CollectionName = Constants.CosmosDb_CollectionName, Uri = new Uri(Constants.CosmosDb_Uri), MasterKey = Constants.CosmosDb_Key }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = Constants.CosmosDb_DatabaseName, CollectionName = "leases", Uri = new Uri(Constants.CosmosDb_Uri), MasterKey = Constants.CosmosDb_Key }; var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("ProductChangeObserverHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <ProductChangeObserver>() .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
public async Task StartAsync() { var feedCollectionInfo = new DocumentCollectionInfo { DatabaseName = _database, CollectionName = _eventContainer, Uri = new Uri(_endpointUri), MasterKey = _authKey }; var leaseCollectionInfo = new DocumentCollectionInfo { DatabaseName = _database, CollectionName = _leaseContainer, Uri = new Uri(_endpointUri), MasterKey = _authKey }; var viewRepository = new CosmosDBViewRepository(_endpointUri, _authKey, _database); var builder = new ChangeFeedProcessorBuilder(); _changeFeedProcessor = await builder .WithHostName("ProjectionHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserverFactory(new EventObserverFactory(_projections, viewRepository)) .WithProcessorOptions(new ChangeFeedProcessorOptions { StartFromBeginning = true }) .BuildAsync(); await _changeFeedProcessor.StartAsync(); }
private static ChangeFeedProcessorBuilder CreateBuilder <T>(DocumentClient client) where T : DocumentBase { var builder = new ChangeFeedProcessorBuilder(); var uri = new Uri(CosmosUrl); var dbClient = new ChangeFeedDocumentClient(client); builder .WithHostName(HostName) .WithFeedCollection(new DocumentCollectionInfo { DatabaseName = typeof(T).Name, CollectionName = "Items", Uri = uri, MasterKey = CosmosKey }) .WithLeaseCollection(new DocumentCollectionInfo { DatabaseName = typeof(T).Name, CollectionName = "Leases", Uri = uri, MasterKey = CosmosKey }) .WithProcessorOptions(new ChangeFeedProcessorOptions { FeedPollDelay = TimeSpan.FromSeconds(15), }) .WithFeedDocumentClient(dbClient) .WithLeaseDocumentClient(dbClient) .WithObserver <DocumentFeedObserver <T> >(); return(builder); }
static async Task RunAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "Sjaas", CollectionName = "Job", Uri = new Uri("to-be-filled"), MasterKey = "to-be-filled" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "Sjaas", CollectionName = "Lease", Uri = new Uri("to-be-filled"), MasterKey = "to-be-filled" }; var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("SjaasWorker") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <SjaasWorker>() .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { Log("ExecuteAsync"); var hostName = _cosmosSettings.HostName; var dbName = _cosmosSettings.DatabaseName; var key = _cosmosSettings.Key; var uri = _cosmosSettings.Uri; DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = dbName, CollectionName = _cosmosSettings.CollectionName, Uri = new Uri(uri), MasterKey = key }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = dbName, CollectionName = _cosmosSettings.LeaseCollectionName, Uri = new Uri(uri), MasterKey = key }; var observerFactory = new CosmosDBObserverFactory(_memoryCache, _log); var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName(hostName) .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserverFactory(observerFactory) .BuildAsync(); Log("before StartAsync"); await processor.StartAsync(); Log("after StartAsync"); await Task.Delay(-1); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); Log("before StopAsync"); await processor.StopAsync(); Log("after StopAsync"); } catch (Exception ex) { Log(ex.ToString()); } }
/// <summary> /// Registers a change feed observer to update changes read on /// change feed to destination collection. Deregisters change feed /// observer and closes process when enter key is pressed /// </summary> /// <returns>A Task to allow asynchronous execution</returns> private async Task RunChangeFeedHostAsync() { string monitoredUri = ConfigurationManager.AppSettings["CosmosDBEndpointUri"]; string monitoredSecretKey = ConfigurationManager.AppSettings["CosmosDBAuthKey"]; string monitoredDbName = ConfigurationManager.AppSettings["DatabaseName"]; string monitoredContainerName = ConfigurationManager.AppSettings["ContainerName"]; // Source collection to be monitored for changes DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(monitoredUri), MasterKey = monitoredSecretKey, DatabaseName = monitoredDbName, CollectionName = monitoredContainerName }; string leaseUri = ConfigurationManager.AppSettings["LeaseUri"]; string leaseSecretKey = ConfigurationManager.AppSettings["LeaseSecretKey"]; string leaseDbName = ConfigurationManager.AppSettings["LeaseDbName"]; string leaseContainerName = ConfigurationManager.AppSettings["LeaseContainerName"]; // Lease Collection managing leases on each of the underlying shards of the source collection being monitored DocumentCollectionInfo leaseContainerInfo = new DocumentCollectionInfo { Uri = new Uri(leaseUri), MasterKey = leaseSecretKey, DatabaseName = leaseDbName, CollectionName = leaseContainerName }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(this.DocumentClient); ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); int feedPollDelayInSeconds = int.Parse(ConfigurationManager.AppSettings["FeedPollDelayInSeconds"]); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(240); feedProcessorOptions.LeaseExpirationInterval = TimeSpan.FromSeconds(240); feedProcessorOptions.FeedPollDelay = TimeSpan.FromMilliseconds(feedPollDelayInSeconds * 1000); feedProcessorOptions.StartFromBeginning = true; feedProcessorOptions.MaxItemCount = 2000; ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(this.HostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseContainerInfo) .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new DocumentFeedObserverFactory(this.DocumentClient)); var result = await builder.BuildAsync(); await result.StartAsync().ConfigureAwait(false); }
/// <summary> /// Registers change feed observer to update changes read on change feed to destination /// collection. Deregisters change feed observer and closes process when enter key is pressed /// </summary> /// <returns>A Task to allow asynchronous execution</returns> public async Task RunChangeFeedHostAsync() { string hostName = Guid.NewGuid().ToString(); // monitored collection info DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(this.monitoredUri), MasterKey = this.monitoredSecretKey, DatabaseName = this.monitoredDbName, CollectionName = this.monitoredCollectionName }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(this.leaseUri), MasterKey = this.leaseSecretKey, DatabaseName = this.leaseDbName, CollectionName = this.leaseCollectionName }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(); ChangeFeedOptions feedOptions = new ChangeFeedOptions(); /* ie customize StartFromBeginning so change feed reads from beginning * can customize MaxItemCount, PartitonKeyRangeId, RequestContinuation, SessionToken and StartFromBeginning */ feedOptions.StartFromBeginning = true; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); // ie. customizing lease renewal interval to 15 seconds // can customize LeaseRenewInterval, LeaseAcquireInterval, LeaseExpirationInterval, FeedPollDelay feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(hostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new DocumentFeedObserverFactory()); // .WithObserver<DocumentFeedObserver>(); or just pass a observer var result = await builder.BuildAsync(); await result.StartAsync(); Console.Read(); await result.StopAsync(); }
private static async Task RunChangeFeedHostAsync() { // monitored collection info DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(cosmosSettings.DbUrl), MasterKey = cosmosSettings.AuthorizationKey, DatabaseName = cosmosSettings.DbName, CollectionName = cosmosSettings.CollectionName }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(cosmosSettings.DbUrl), MasterKey = cosmosSettings.AuthorizationKey, DatabaseName = cosmosSettings.DbName, CollectionName = cosmosSettings.LeaseCollectionName }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(); ChangeFeedOptions feedOptions = new ChangeFeedOptions { /* ie customize StartFromBeginning so change feed reads from beginning * can customize MaxItemCount, PartitonKeyRangeId, RequestContinuation, SessionToken and StartFromBeginning */ StartFromBeginning = true }; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); // ie. customizing lease renewal interval to 15 seconds // can customize LeaseRenewInterval, LeaseAcquireInterval, LeaseExpirationInterval, FeedPollDelay feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(hostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new DocumentFeedObserverFactory()); //.WithObserver<DocumentFeedObserver>(); If no factory then just pass an observer var result = await builder.BuildAsync(); await result.StartAsync(); Console.Read(); await result.StopAsync(); }
static async Task DoProcessingAsync() { string hostName = Guid.NewGuid().ToString(); DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = Constants.CosmosDb_DatabaseName, CollectionName = Constants.CosmosDb_CollectionName, Uri = new Uri(Constants.CosmosDb_Uri), MasterKey = Constants.CosmosDb_Key }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = Constants.CosmosDb_DatabaseName, CollectionName = "Clothing", Uri = new Uri(Constants.CosmosDb_Uri), MasterKey = Constants.CosmosDb_Key }; var builder = new ChangeFeedProcessorBuilder(); ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); feedProcessorOptions.StartFromBeginning = true; //ChangeFeedEventHost host = new ChangeFeedEventHost("ProductChangeObserverHost", feedCollectionInfo, leaseCollectionInfo, feedOptions, feedHostOptions); var processor = await builder .WithHostName("ProductChangeObserverHost-" + hostName) .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) //.WithObserver<ProductChangeObserver>() .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new ProductFeedObserverFactory()) .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
/// <summary> /// Registers change feed observer to update changes read on change feed to destination /// collection. Deregisters change feed observer and closes process when enter key is pressed /// </summary> /// <returns>A Task to allow asynchronous execution</returns> public async Task RunChangeFeedHostAsync() { string hostName = Guid.NewGuid().ToString(); // monitored collection info DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(this.monitoredUri), MasterKey = this.monitoredSecretKey, DatabaseName = this.monitoredDbName, CollectionName = this.monitoredCollectionName }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(this.leaseUri), MasterKey = this.leaseSecretKey, DatabaseName = this.leaseDbName, CollectionName = this.leaseCollectionName }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(); ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.StartFromBeginning = true; // ie. customizing lease renewal interval to 15 seconds // can customize LeaseRenewInterval, LeaseAcquireInterval, LeaseExpirationInterval, FeedPollDelay feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(hostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithProcessorOptions(feedProcessorOptions) .WithPartitionLoadBalancingStrategy(new LoadBalancingStrategy()) .WithObserverFactory(new DocumentFeedObserverFactory()); var result = await builder.BuildAsync(); await result.StartAsync(); Console.Read(); await result.StopAsync(); }
static async Task RunAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "DemoDatabase", CollectionName = "DemoCollection", Uri = new Uri("endpoint"), MasterKey = "" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "DemoDatabase", CollectionName = "leases", Uri = new Uri("endpoint"), MasterKey = "key" }; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); // ie. customizing lease renewal interval to 15 seconds // can customize LeaseRenewInterval, LeaseAcquireInterval, LeaseExpirationInterval, FeedPollDelay feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); feedProcessorOptions.StartFromBeginning = true; //feedProcessorOptions.StartTime = DateTime.Now - TimeSpan.FromDays(1); var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("SampleHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <SampleObserver>() // add as many sample observers (aka consumers as needed) via WithObserver<> .WithProcessorOptions(feedProcessorOptions) .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
// Boilerplate from the ChangeFeedProcessor library. public async Task RunChangeFeedHostAsync() { string hostName = "ChatHost" + DateTime.Now.Ticks.ToString(); // The collection to be observed is registered here. DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(Keys.CosmosDBUri), MasterKey = Keys.CosmosDBKey, DatabaseName = GroupSelectionPageViewModel.SelectedDBName, CollectionName = "Messages" }; // The lease is a collection where the changes are temporary stored. DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(Keys.CosmosDBUri), MasterKey = Keys.CosmosDBKey, DatabaseName = GroupSelectionPageViewModel.SelectedDBName, CollectionName = "Lease" }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(); ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); feedProcessorOptions.StartFromBeginning = true; ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(hostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new DocumentFeedObserverFactory()); // A new ChangeFeedProcessor is built and then run asynchronously. var result = await builder.BuildAsync(); await result.StartAsync(); }
static async Task RunAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "pinball-leaderboard", CollectionName = "leaderboard", Uri = new Uri("https://sqlcomos2019.documents.azure.com:443/"), MasterKey = "0oyBJST0UzbkkU2hIYMmePZAEjBoTPTW7EEqUCL7WPhxNN2DNai8TwpKfnQrE6mlN4R93PGe08fGIoK2FtAYfw==" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "pinball-leaderboard", CollectionName = "leasesScore", Uri = new Uri("https://sqlcomos2019.documents.azure.com:443/"), MasterKey = "0oyBJST0UzbkkU2hIYMmePZAEjBoTPTW7EEqUCL7WPhxNN2DNai8TwpKfnQrE6mlN4R93PGe08fGIoK2FtAYfw==" }; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(5); feedProcessorOptions.StartFromBeginning = false; var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("LeaderboardHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <ChangeFeedObserver>() .WithProcessorOptions(feedProcessorOptions) .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
static async Task RunAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "movies", CollectionName = "feedraw", Uri = new Uri("< your Cosmos DB ep >"), MasterKey = "< of course your access key >" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "movies", CollectionName = "feedleases", Uri = new Uri("your Cosmos DB access key"), MasterKey = "< your access key > " }; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(5); feedProcessorOptions.StartFromBeginning = false; var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("ChangeFeedHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <ChangeFeedListener>() .WithProcessorOptions(feedProcessorOptions) .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
static async Task RunAsync() { DocumentCollectionInfo feedCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "pinball-leaderboard", CollectionName = "leaderboard", Uri = new Uri("<account-connection-string>"), MasterKey = "<primary-key>" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo() { DatabaseName = "pinball-leaderboard", CollectionName = "leases", Uri = new Uri("<account-connection-string>"), MasterKey = "<primary-key>" }; ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(5); feedProcessorOptions.StartFromBeginning = false; var builder = new ChangeFeedProcessorBuilder(); var processor = await builder .WithHostName("LeaderboardHost") .WithFeedCollection(feedCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithObserver <ChangeFeedObserver>() .WithProcessorOptions(feedProcessorOptions) .BuildAsync(); await processor.StartAsync(); Console.WriteLine("Change Feed Processor started. Press <Enter> key to stop..."); Console.ReadLine(); await processor.StopAsync(); }
// Boilerplate from the ChangeFeedProcessor library. public async Task RunChangeFeedHostAsync() { string hostName = "FlashHost" + DateTime.Now.Ticks.ToString(); DocumentCollectionInfo documentCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(Keys.CosmosDBUri), MasterKey = Keys.CosmosDBKey, DatabaseName = GroupSelectionPageViewModel.SelectedDBName, CollectionName = "Flashcards" }; DocumentCollectionInfo leaseCollectionInfo = new DocumentCollectionInfo { Uri = new Uri(Keys.CosmosDBUri), MasterKey = Keys.CosmosDBKey, DatabaseName = GroupSelectionPageViewModel.SelectedDBName, CollectionName = "FlashLease" }; DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(); ChangeFeedProcessorOptions feedProcessorOptions = new ChangeFeedProcessorOptions(); feedProcessorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15); feedProcessorOptions.StartFromBeginning = true; ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder(); builder .WithHostName(hostName) .WithFeedCollection(documentCollectionInfo) .WithLeaseCollection(leaseCollectionInfo) .WithProcessorOptions(feedProcessorOptions) .WithObserverFactory(new DocumentFeedObserverFactory()); var result = await builder.BuildAsync(); await result.StartAsync(); }
public IChangeFeedProcessor CreateChangeFeedProcessor(string monitoredUri, string monitoredSecretKey, string monitoredDbName, string monitoredCollectionName, string leaseUri, string leaseSecretKey, string leaseDbName, string leaseCollectionName) { string hostName = Guid.NewGuid().ToString(); DocumentCollectionInfo documentCollectionLocation = new DocumentCollectionInfo { Uri = new Uri(monitoredUri), MasterKey = monitoredSecretKey, DatabaseName = monitoredDbName, CollectionName = monitoredCollectionName }; DocumentCollectionInfo leaseCollectionLocation = new DocumentCollectionInfo { Uri = new Uri(leaseUri), MasterKey = leaseSecretKey, DatabaseName = leaseDbName, CollectionName = leaseCollectionName }; DocumentClient monitorClient = new DocumentClient( serviceEndpoint: new Uri(monitoredUri), authKeyOrResourceToken: monitoredSecretKey, handler: new HttpClientHandler { ServerCertificateCustomValidationCallback = (a, b, c, d) => true }, connectionPolicy: new ConnectionPolicy { EnableEndpointDiscovery = false, ConnectionMode = ConnectionMode.Gateway, ConnectionProtocol = Protocol.Tcp }); DocumentClient leaseClient = new DocumentClient( serviceEndpoint: new Uri(leaseUri), authKeyOrResourceToken: leaseSecretKey, handler: new HttpClientHandler { ServerCertificateCustomValidationCallback = (a, b, c, d) => true }, connectionPolicy: new ConnectionPolicy { EnableEndpointDiscovery = false, ConnectionMode = ConnectionMode.Gateway, ConnectionProtocol = Protocol.Tcp }); var tracelogProvider = new TraceLogProvider(); using (tracelogProvider.OpenNestedContext(hostName)) { LogProvider.SetCurrentLogProvider(tracelogProvider); } var builder = new ChangeFeedProcessorBuilder(); var processor = builder .WithHostName(hostName) .WithFeedCollection(documentCollectionLocation) .WithLeaseCollection(leaseCollectionLocation) .WithFeedDocumentClient(monitorClient) .WithLeaseDocumentClient(leaseClient) .WithObserverFactory(new CosmosDbChangeFeedObserverFactory <Customer>()) .WithProcessorOptions(new ChangeFeedProcessorOptions { LeasePrefix = $"NCache--", StartTime = DateTime.Now }) .BuildAsync() .Result; processor.StartAsync(); return(processor); }