我确实从该资源中获得了 Cosmos DB 更改源的代码示例
我能够成功编译和运行代码。
这是更改提要调用的代码
private static async Task<ChangeFeedProcessor> StartChangeFeedProcessorAsync(
CosmosClient cosmosClient,
IConfiguration configuration)
{
string databaseName = "changefeedsample";// configuration["SourceDatabaseName"];
string sourceContainerName = "source";// configuration["SourceContainerName"];
string leaseContainerName = "leases";// configuration["LeasesContainerName"];
Container leaseContainer = cosmosClient.GetContainer(databaseName, leaseContainerName);
ChangeFeedProcessor changeFeedProcessor = cosmosClient.GetContainer(databaseName, sourceContainerName)
.GetChangeFeedProcessorBuilder<ToDoItem>(processorName: "changeFeedSample", onChangesDelegate: HandleChangesAsync)
.WithInstanceName("consoleHost")
.WithLeaseContainer(leaseContainer)
.Build();
Console.WriteLine("Starting Change Feed Processor...");
await changeFeedProcessor.StartAsync();
Console.WriteLine("Change Feed Processor started.");
return changeFeedProcessor;
}
这是对更改提要执行的操作的代码
static async Task HandleChangesAsync(IReadOnlyCollection<ToDoItem> changes, CancellationToken cancellationToken)
{
Console.WriteLine("Started handling changes...");
foreach (ToDoItem item in changes)
{
Console.WriteLine($"Detected operation for item with id {item.id}, created at {item.creationTime}.");
// Simulate some asynchronous operation
await Task.Delay(10);
}
Console.WriteLine("Finished handling changes.");
}
我确实看到了如何在插入时触发该操作;但是,有没有办法判断是否对更新采取了行动。有没有办法分辨哪个是哪个,从另一个中分辨出来。有没有办法获得有关更新/添加数据的更多详细信息
非常感谢您提前