IReliable ReadWrite DocumentClient 在 Documentdb 中缺少分区解析器

IReliableReadWriteDocumentClient is missing PartitionResolver in Document DB

当返回 DocumentClient AsReliable 时,它没有 PartitionResolver。有什么办法可以解决这个问题?

var documentClient = new DocumentClient(new Uri(endPointUrl), authorizationKey);

var documentRetryStrategy = new DocumentDbRetryStrategy(RetryStrategy.DefaultExponential) { FastFirstRetry = true };
return documentClient.AsReliable(documentRetryStrategy);

您可以访问底层的 DocumentClient 对象来注册 PartitionResolvers。

您从 .AsReliable(..) 获得的 IReliableReadWriteDocumentClient 实现只是原始 DocumentClient 的包装器,它在重试块中执行原始(底层)客户端的每个方法使用提供的重试策略。没有魔法。内置 DocumentDbRetryStrategy 旨在消除大多数瞬态 network/service/throttling 问题。

回答您最初的问题 - 您可以在使用 .AsReliable(..) 包装之前在原始客户端上设置 PartitionResolvers,或者您稍后可以通过 UnderlyingClient 属性 访问该集合. UnderlyingClient 属性 持有传递给 .AsReliable(..) 扩展方法的同一个实例。

关于使用 DocumentClientIReliableReadWriteDocumentClient 的最佳实践:如果您需要在客户端和服务器之间进行更可靠的通信,那将自动重试上述暂时性故障 - 那么您应该考虑使用 .AsReliable(..)。如果您的方案不需要将所有文档都保存在存储中(例如,在 logging/trace 的情况下)并且无论如何您都会 "swallow" 所有异常 - 那么使用 [=12 没有任何问题=]直接减少额外重试的时间。