Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private static async Task <IRemainingWorkEstimator> CreateEstimatorAsync(string uri, string key, string collection)
        {
            IChangeFeedDocumentClient dbClient = new ChangeFeedDocumentClient(new DocumentClient(new Uri(uri), key));

            var builder = new ChangeFeedProcessorBuilder()
                          .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);

            return(await builder.BuildEstimatorAsync());
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }