首页 > 解决方案 > 如何处理与 Azure 存储等服务的连接

问题描述

我的函数将数据存储到 Azure Data Lakta Storage Gen 1。但我遇到了错误

发送请求时出错。
当我调查时,我知道我在 azure 函数中的连接超过了 8k,然后它就坏了。这是我的代码(附加到文件 Azure DataLakeStorage Gen 1)

//This for authorizing azure data lake storage gen 1
 await InitADLInfo(adlsAccountName);

DataLakeStoreFileSystemManagementClient _adlsFileSystemClient;

//Here is my code to append data lake storage gen 1
 using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(buffer)))
 {
    await _adlsFileSystemClient.FileSystem.AppendAsync(_adlsAccountName, path, stream);                         
 }

当每个附加结束时如何处理它。我尝试处置

_adlsFileSystemClient.Dispose();

但它没有处理任何东西。我的连接会起来。

标签: azureazure-data-lake

解决方案


我读了这个 https://www.troyhunt.com/break-azure-functions-with-too-many-connections/ 1 我已经建立了连接。只需使用DO NOT create a new client with every function invocation. 示例代码:

// Create a single, static HttpClient
private static HttpClient httpClient = new HttpClient();

public static async Task Run(string input)
{
    var response = await httpClient.GetAsync("http://example.com");
    // Rest of function
}

推荐阅读