如何使用java在Cosmos DB中设置重试策略



如何设置Retry策略,其中使用java将记录推送到cosmosDB。

如果第一次推送记录失败,我想重试推送记录。我想在间隔2秒后重试推送5次。

我如何在java中进行这样的更改我读过java中的ConnectionPolicy,但无法理解它如何完全满足我的需求。

参考链接:https://learn.microsoft.com/bs-latn-ba/azure/cosmos-db/performance-tips-java

代码:

retryOptions = new RetryOptions();
retryOptions.setMaxRetryAttemptsOnThrottledRequests(5);
retryOptions.setMaxRetryWaitTimeInSeconds(10);
connectionPolicy = new ConnectionPolicy();
connectionPolicy.setRetryOptions(retryOptions);
documentClient = new DocumentClient(END_POINT,
MASTER_KEY, connectionPolicy,
ConsistencyLevel.Session);

您可以使用ConnectionPolicy.setRetryOptions(RetryOptions retryOptions)方法创建RetryOption的实例,setMaxRetryAttemptsOnThrottledRequests作为5setMaxRetryWaitTimeInSeconds作为10(2秒x 5次重试(。

最新更新