gpt4 book ai didi

c# - 从 DocumentDB 查询时出现异常 : Microsoft. Azure.Documents.RequestRateTooLargeException

转载 作者:太空狗 更新时间:2023-10-29 22:26:10 24 4
gpt4 key购买 nike

y 查询类似于

this.ProcessRequestSync(() => this.Client.CreateDocumentQuery<Model>(this.DocumentDBCollectionLink).Where(d => d.name.Equals(name) && d.code.Equals(code) && d.Type.Equals(this.documentType) && d.CreatedBy.Equals(myName).ToList<Model>());

public dynamic ProcessRequestSync(Func<dynamic> getRequest)
{
var delay = TimeSpan.Zero;
var minDelayTime = new TimeSpan(0, 0, 1);
for (;;)
{
try
{
Thread.Sleep(delay);
return getRequest();
}
catch (DocumentClientException documentClientException)
{
var statusCode = (int)documentClientException.StatusCode;
if (statusCode == 429 || statusCode == 503)
{
string errorMessage = string.Format("failed at DocumentDB with {0} status and {1} retry time", statusCode, documentClientException.RetryAfter);
this.Logger.Log(errorMessage );

// Back off if the request rate is too large or the service is temporarily unavailable
delay = TimeSpan.Compare(documentClientException.RetryAfter, minDelayTime) >= 0 ? documentClientException.RetryAfter: minDelayTime;
}
else
{
throw;
}
}
}
}

这是 requestRateTooLarge 异常引发时的重试逻辑方法。

我不确定,它是否工作正常,

一次查询和插入大约 4000 条记录时出现异常:Microsoft.Azure.Documents.RequestRateTooLargeException,

我使用了相同的重试逻辑来插入,它工作正常。我没有收到任何错误,也成功插入了所有记录,但无法获取查询数据。

最佳答案

基于@aravind Ramachandra 和@Ryan CrawCour 上面/下面的回答,这就是我用来解决这个问题的方法。

    public async Task SaveToDocDb(dynamic jsonDocToSave)
{

using (var client = new DocumentClient(endpoint, authKey))
{
var queryDone = false;
while (!queryDone)
{
try
{
await client.CreateDocumentAsync(docCollectionlink, jsonDocToSave);
queryDone = true;
}
catch (DocumentClientException documentClientException)
{
var statusCode = (int)documentClientException.StatusCode;
if (statusCode == 429 || statusCode == 503)
Thread.Sleep(documentClientException.RetryAfter);
else
throw;
}
catch (AggregateException aggregateException)
{
if(aggregateException.InnerException.GetType() == typeof(DocumentClientException)){

var docExcep = aggregateException.InnerException as DocumentClientException;
var statusCode = (int)docExcep.StatusCode;
if (statusCode == 429 || statusCode == 503)
Thread.Sleep(docExcep.RetryAfter);
else
throw;
}
else
throw;
}
}
}
}

关于c# - 从 DocumentDB 查询时出现异常 : Microsoft. Azure.Documents.RequestRateTooLargeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29275447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com