Azure cosmosdb CosmosDb更改源处理器,文件属性值错误,如何处理?
我在我的宇宙数据库中有一个毒药记录,我用a读到了。Azure cosmosdb CosmosDb更改源处理器,文件属性值错误,如何处理?,azure-cosmosdb,Azure Cosmosdb,我在我的宇宙数据库中有一个毒药记录,我用a读到了。 毒药记录的属性中包含null,其中应该有一个值。 问题是我没有例外 我想为此记录一个错误。首选的方式是什么 在“调试输出”窗口中,我看到的不是异常,而是: DocDBTrace Warning: 0 : Exception Microsoft.Azure.Cosmos.ChangeFeed.Exceptions.ObserverException: RequestUri: , Exception has been thrown by
毒药记录的属性中包含null,其中应该有一个值。
问题是我没有例外 我想为此记录一个错误。首选的方式是什么
在“调试输出”窗口中,我看到的不是异常,而是:
DocDBTrace Warning: 0 : Exception Microsoft.Azure.Cosmos.ChangeFeed.Exceptions.ObserverException: RequestUri: ,
Exception has been thrown by the Observer.,
at Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing.FeedProcessorCore`1.DispatchChangesAsync(ResponseMessage response, CancellationToken cancellationToken)
...
DocDBTrace Warning: 0 : Exception Newtonsoft.Json.JsonSerializationException: RequestUri: , Error converting value {null}
to type 'System.DateTime'. Path 'Documents[0].Start', line 1, position 464.,
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
...
上面的文档[0].Start
来自我的DTO
public class CustomerEntity{
...
public DateTime Start {get; set;}
...
}
The setup is:
changeFeedProcessor=cosmosClient.GetContainer(…)
.GetChangeFeedProcessorBuilder(…,searchSyncService.HandleChangesAsync)
.WithLeaseConfiguration()
...
.Build()
内部异步任务HandleChangesAsync(IReadOnlyCollection更改,…)
{
...
}
我目前有两种可能的解决方案。
第一个是捕获异常,当框架试图反序列化到我的CustomerEntity时,该异常显然在某处抛出。
问题是我不知道怎么做。
另一种解决方案是使用``调用`GetChangeFeedProcessorBuilder`并自己反序列化对象。
这应该是可行的,但这是“正确”的方法吗?
问题在于,如果您将具有不同模式的文档放入容器/集合中,您将获得其中任何一个模式的更改,因此用于读取它们的类应支持所有可能的更改
一种可能是让您的客户属性类拥有:
[JsonProperty("Start", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? Start { get; set; }
因此,您可以检查change.Start.HasValue
internal async Task HandleChangesAsync(IReadOnlyCollection<CustomerEntity> changes, ...)
{
...
}
I have presently 2 possible solutions.
The first is to catch the exception that is obviously thrown somewhere when the framework tries to deserialise to my CustomerEntity.
The problem is that I don't know how.
The other solution is to call `GetChangeFeedProcessorBuilder` with `<object>` instead and deseralise the object myself.
This is should be doable but is it the "correct" way?
[JsonProperty("Start", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? Start { get; set; }