【问题标题】:Cosmos Db Change Feed do not give the desired resultCosmos Db 更改 Feed 未给出预期结果
【发布时间】:2020-12-01 14:29:15
【问题描述】:

我正在尝试按照以下代码从 Cosmos db Change Feed 中的受监控 Db 中获取所有更改。我正在尝试不同的持续时间,例如今天发生的变化或过去 7 天发生的变化或整体发生的变化。现在,在所有情况下,我在第一次获得所有更改,而在第二次运行中没有任何更改,除非有更改即将到来。我想知道我在这里做错了什么,如果我每次运行都必须在上周进行更改,如果我的以下代码不正确,我应该如何配置更改提要。提前致谢

 private static CosmosClient Client { get; set; }
    static void Main(string[] args)
    {
        Task.Run(async () =>
        {
            Client = new CosmosClient("AccountEndpoint = https://test.documents.azure.com:443/;AccountKey=FW5yvDA==;");
            var database = Client.GetDatabase("twstDatabase");
            var container = database.GetContainer("TestContainer");
            var leaseContainer = database.GetContainer("leases");

            var cfp = container.GetChangeFeedProcessorBuilder<dynamic>("cfpLibraryDThird", ProcessChanges)
                .WithLeaseContainer(leaseContainer)
                .WithInstanceName("Change Feed Instance Demo") 
// I change the instance name for different start time
                    .WithStartTime(DateTime.Today.AddDays(-7).ToUniversalTime())
                    //.WithStartTime(DateTime.MinValue.ToUniversalTime())
                    .Build();
                await cfp.StartAsync();
                Console.WriteLine("Started Change feed processor- press key to stop");
                Console.ReadKey(true);
                await cfp.StopAsync();
            }).Wait();
        }

        static async Task ProcessChanges(IReadOnlyCollection<dynamic> docs, CancellationToken cancellationToken)
        {
            foreach (var doc in docs)
            {
                Console.WriteLine($"Document {doc.id} has changed");
                
            }
        }
    }
}

【问题讨论】:

    标签: azure-cosmosdb azure-cosmosdb-changefeed


    【解决方案1】:

    它被固定在 3.15.1。我更新了包,它解决了问题。

    【讨论】:

      【解决方案2】:

      这是 3.15 的一个错误,您可以在此处跟踪此问题 https://github.com/Azure/azure-cosmos-dotnet-v3/issues/2031

      【讨论】:

      • 但我的问题是,如果我不想处理所有更改并仅处理过去 7 天内发生的更改,该怎么办。我提供了一个 WithStartTime 值,但当我第一次运行它时,我仍然会得到所有更改
      • 所以我创建了一个新容器,在上面的代码中将其 Id 作为 Lease Container 并将 Time 设置为 (DateTime.Today.AddDays(-7).ToUniversalTime()) 我仍然得到我监控的数据库中的所有文档。你最后试过了吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2016-01-30
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多