Beispiel #1
0
        private static async Task <IChangeFeedProcessor> RunChangeFeedProcessorAsync(string uri, string key, string collection)
        {
            IChangeFeedDocumentClient dbClient = new ChangeFeedDocumentClient(new DocumentClient(new Uri(uri), key));

            dbClient = new QoSMeteringChangeFeedDocumentClient(dbClient, new QoSMeteringReporter());


            var builder = new ChangeFeedProcessorBuilder()
                          .WithObserver <ConsoleObserver>()
                          .WithHostName("console_app_host")
                          .WithFeedCollection(new DocumentCollectionInfo()
            {
                Uri            = new Uri(uri),
                MasterKey      = key,
                CollectionName = collection,
                DatabaseName   = DbName
            })
                          .WithLeaseCollection(new DocumentCollectionInfo()
            {
                CollectionName = $"{collection}.Lease.ConsoleApp",
                DatabaseName   = DbName,
                Uri            = new Uri(uri),
                MasterKey      = key
            })
                          .WithFeedDocumentClient(dbClient)
                          .WithLeaseDocumentClient(dbClient);

            var processor = await builder.BuildAsync();

            var estimator = await builder.BuildEstimatorAsync();

            await processor.StartAsync().ConfigureAwait(false);

            return(processor);
        }
Beispiel #2
0
        internal virtual async Task StartProcessorAsync()
        {
            if (_host == null)
            {
                _host = await _hostBuilder.BuildAsync();
            }

            await _host.StartAsync();
        }
        public async Task BuildThrowsWhenNoneOfLeaseCollectionInfoOrLeaseStoreManagerSpecified()
        {
            var builder = new ChangeFeedProcessorBuilder()
                          .WithHostName("host")
                          .WithFeedCollection(CollectionInfo)
                          .WithFeedDocumentClient(CreateMockDocumentClient())
                          .WithObserverFactory(Mock.Of <IChangeFeedObserverFactory>());

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await builder.BuildAsync());
        }
Beispiel #4
0
        /// <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);
        }
        public async Task BuildWhenOnlyLeaseStoreManagerSpecified()
        {
            var builder = new ChangeFeedProcessorBuilder()
                          .WithHostName("host")
                          .WithFeedCollection(CollectionInfo)
                          .WithFeedDocumentClient(CreateMockDocumentClient())
                          .WithObserverFactory(Mock.Of <IChangeFeedObserverFactory>())
                          .WithLeaseStoreManager(Mock.Of <ILeaseStoreManager>());

            await builder.BuildAsync();
        }
Beispiel #6
0
        /// <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();
        }
        /// <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();
        }
Beispiel #9
0
        // 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();
        }
Beispiel #10
0
        // 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();
        }
Beispiel #11
0
        private static async Task <IChangeFeedProcessor> RunChangeFeedProcessorAsync(string uri, string key, string collection)
        {
            IChangeFeedDocumentClient dbClient = new ChangeFeedDocumentClient(new DocumentClient(new Uri(uri), key));

            var builder = new ChangeFeedProcessorBuilder()
                          .WithProcessorOptions(new ChangeFeedProcessorOptions()
            {
                CheckpointFrequency = new CheckpointFrequency()
                {
                    ExplicitCheckpoint = true
                }
            })
                          .WithObserverFactory(new ConsoleObserverFactory(TimeSpan.FromSeconds(10)))
                          .WithHostName("console_app_host")
                          .WithFeedCollection(new DocumentCollectionInfo()
            {
                Uri            = new Uri(uri),
                MasterKey      = key,
                CollectionName = collection,
                DatabaseName   = DbName
            })
                          .WithLeaseCollection(new DocumentCollectionInfo()
            {
                CollectionName = $"{collection}.Lease.ConsoleApp",
                DatabaseName   = DbName,
                Uri            = new Uri(uri),
                MasterKey      = key
            })
                          .WithFeedDocumentClient(dbClient)
                          .WithLeaseDocumentClient(dbClient);

            var processor = await builder.BuildAsync();

            await processor.StartAsync().ConfigureAwait(false);

            return(processor);
        }
 public async Task BuildThrowsWhenLeaseCollectionPartitionedNotById()
 {
     SetupBuilderForPartitionedLeaseCollection("/not_id");
     await Assert.ThrowsAsync <ArgumentException>(async() => await builder.BuildAsync());
 }