azure-cosmosdb - 避免 - 由于系统缺少足够的缓冲区空间或队列已满,因此无法对套接字执行操作
问题描述
使用 cosmos DB 时,我从 Azure Function App 收到以下错误。我对 HttpClient 也有同样的看法,但似乎通过做 HttpClient static 来解决这个问题。你能通过将 CosmosDB 客户端设为静态来解决同样的问题吗?就像是:
public class DocRepoCoach
{
public string ConnStr { get; set; }
public Container XX1Container { get; set; }
public Container XX2Container { get; set; }
**public static CosmosClient Client { get; set; }**
public DocRepoCoach(string connectionString)
{
ConnStr = connectionString;
var options = new CosmosClientOptions() { AllowBulkExecution = true, MaxRetryAttemptsOnRateLimitedRequests = 1000 };
Client = new CosmosClient(ConnStr, options);
XX1Container = Client.GetContainer("XXXAPI", "XX");
XX2Container = Client.GetContainer("XXXAPI", "XX");
}
}
解决方案
是的,请将其设为静态。Azure 函数的推荐做法是在应用程序的整个生命周期内使用 Singleton 客户端。当您使用静态客户端时,CosmosClient 可以管理连接。
以下是建议
- 不要在每次函数调用时都创建一个新客户端。
- 请创建一个每个函数调用都可以使用的单个静态客户端。
- 如果不同的功能使用相同的服务,请考虑在共享帮助程序类中创建单个静态客户端。
这些也记录在Azure 文档中
推荐阅读
- c# - C#。定义不同泛型类型的元素列表,但都具有相同的基本类型
- apache-spark-sql - 向 Delta Lake 中的现有表添加新列(Gen2 blob 存储)
- arrays - 如何在 ruby 中使用 rindex 查找索引
- java - 如何使文本框两个字段中数据的条件满足?
- python - 直接从命令行将文件导入python程序
- python - 将默认值传递给 **kwargs
- android-studio - 我如何解决这个在 android studio 中构建失败的问题?
- java - java 11 lambda,按相同属性和具有特定条件的过滤器聚合
- python - 关于子进程模块和关键字参数shell
- cassandra - Apache Cassandra 的 DataStax Bulk Loader 未在 Windows 上安装