public async Task <IChangeFeedProcessor> RunChangeFeedHostAsync()
        {
            string hostName = Guid.NewGuid().ToString();

            Trace.TraceInformation("Host name {0}", hostName);

            // monitored collection info
            DocumentCollectionInfo documentCollectionLocation = new DocumentCollectionInfo
            {
                Uri            = new Uri(this.config.MonitoredUri),
                MasterKey      = this.config.MonitoredSecretKey,
                DatabaseName   = this.config.MonitoredDbName,
                CollectionName = this.config.MonitoredCollectionName
            };

            // lease collection info
            DocumentCollectionInfo leaseCollectionLocation = new DocumentCollectionInfo
            {
                Uri            = new Uri(this.config.LeaseUri),
                MasterKey      = this.config.LeaseSecretKey,
                DatabaseName   = this.config.LeaseDbName,
                CollectionName = this.config.LeaseCollectionName
            };

            // destination collection info
            DocumentCollectionInfo destCollInfo = new DocumentCollectionInfo
            {
                Uri            = new Uri(this.config.DestUri),
                MasterKey      = this.config.DestSecretKey,
                DatabaseName   = this.config.DestDbName,
                CollectionName = this.config.DestCollectionName
            };

            ChangeFeedProcessorOptions processorOptions = new ChangeFeedProcessorOptions();

            processorOptions.StartFromBeginning = true;

            processorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(15);

            Trace.TraceInformation("Processor options Starts from Beginning - {0}, Lease renew interval - {1}",
                                   processorOptions.StartFromBeginning,
                                   processorOptions.LeaseRenewInterval.ToString());

            DocumentClient destClient = new DocumentClient(destCollInfo.Uri, destCollInfo.MasterKey);
            DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory(destClient, destCollInfo);
            var processor = await new ChangeFeedProcessorBuilder()
                            .WithObserverFactory(docObserverFactory)
                            .WithHostName(hostName)
                            .WithFeedCollection(documentCollectionLocation)
                            .WithLeaseCollection(leaseCollectionLocation)
                            .WithProcessorOptions(processorOptions)
                            .BuildAsync();
            await processor.StartAsync().ConfigureAwait(false);

            return(processor);
        }
        public async Task <IChangeFeedProcessor> RunChangeFeedHostAsync()
        {
            string hostName = Guid.NewGuid().ToString();

            Trace.TraceInformation("Host name {0}", hostName);

            // monitored collection info
            var documentCollectionLocation = new DocumentCollectionInfo
            {
                Uri            = new Uri(this.config.MonitoredUri),
                MasterKey      = this.config.MonitoredSecretKey,
                DatabaseName   = this.config.MonitoredDbName,
                CollectionName = this.config.MonitoredCollectionName
            };

            var policy = new ConnectionPolicy()
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            };

            policy.PreferredLocations.Add("North Europe");

            // lease collection info
            var leaseCollectionLocation = new DocumentCollectionInfo
            {
                Uri              = new Uri(this.config.LeaseUri),
                MasterKey        = this.config.LeaseSecretKey,
                DatabaseName     = this.config.LeaseDbName,
                CollectionName   = this.config.LeaseCollectionName,
                ConnectionPolicy = policy
            };

            // destination collection info
            var destCollInfo = new DocumentCollectionInfo
            {
                Uri            = new Uri(this.config.DestUri),
                MasterKey      = this.config.DestSecretKey,
                DatabaseName   = this.config.DestDbName,
                CollectionName = this.config.DestCollectionName
            };

            var processorOptions = new ChangeFeedProcessorOptions();

            if (config.DataAgeInHours.HasValue)
            {
                if (config.DataAgeInHours.Value >= 0)
                {
                    processorOptions.StartTime = DateTime.UtcNow.Subtract(TimeSpan.FromHours(config.DataAgeInHours.Value));
                }
            }
            else
            {
                processorOptions.StartFromBeginning = true;
            }

            processorOptions.LeaseRenewInterval = TimeSpan.FromSeconds(30);

            Trace.TraceInformation("Processor options Starts from Beginning - {0}, Lease renew interval - {1}",
                                   processorOptions.StartFromBeginning,
                                   processorOptions.LeaseRenewInterval.ToString());

            processorOptions.MaxItemCount = 1000;
            var destClient = new DocumentClient(destCollInfo.Uri, destCollInfo.MasterKey,
                                                new ConnectionPolicy()
            {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            },
                                                ConsistencyLevel.Eventual);

            var docTransformer = new DefaultDocumentTransformer();

            BlobContainerClient containerClient = null;

            if (!String.IsNullOrEmpty(config.BlobConnectionString))
            {
                BlobServiceClient blobServiceClient = new BlobServiceClient(config.BlobConnectionString);
                containerClient = blobServiceClient.GetBlobContainerClient(config.BlobContainerName);
                await containerClient.CreateIfNotExistsAsync();
            }

            var docObserverFactory = new DocumentFeedObserverFactory(config.SourcePartitionKeys, config.TargetPartitionKey, destClient, destCollInfo, docTransformer, containerClient);

            changeFeedProcessor = await new ChangeFeedProcessorBuilder()
                                  .WithObserverFactory(docObserverFactory)
                                  .WithHostName(hostName)
                                  .WithFeedCollection(documentCollectionLocation)
                                  .WithLeaseCollection(leaseCollectionLocation)
                                  .WithProcessorOptions(processorOptions)
                                  .WithFeedDocumentClient(new DocumentClient(documentCollectionLocation.Uri, documentCollectionLocation.MasterKey, policy, ConsistencyLevel.Eventual))
                                  .BuildAsync();
            await changeFeedProcessor.StartAsync().ConfigureAwait(false);

            return(changeFeedProcessor);
        }