本地 Azure Function 启动使用错误的 Azurite 服务地址

问题描述 投票:0回答:1

我正在尝试使用使用 Blob 存储的 Visual Studio 22 在本地运行 Azure 函数(.NET 6、HTTP 触发器)。 Azurite 作为 VS 中的服务依赖项自动安装并启动。我在 Windows 10 下操作。

Stream.DataLakeTransaction: azurite.cmd --location "\AppData\Local\.vstools\azurite" --debug "AppData\Local\.vstools\azurite\debug.log" --skipApiVersionCheck
{ProjectName}: Azurite Blob service is starting at http://127.0.0.1:10000
{ProjectName}: Azurite Blob service is successfully listening at http://127.0.0.1:10000
{ProjectName}: Azurite Queue service is starting at http://127.0.0.1:10001
{ProjectName}: Azurite Queue service is successfully listening at http://127.0.0.1:10001
{ProjectName}: Azurite Table service is starting at http://127.0.0.1:10002
I{ProjectName}: Azurite Table service is successfully listening at http://127.0.0.1:10002

在我的

local.settings.json
文件中,我有以下配置
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
,它应该解析为默认的 Azurite 地址,例如 Blob 服务的端口 10000。但发生的情况是,由于某种原因,该函数在启动时尝试在
localhost:5016/
访问它,但由于服务未在该端口上运行而失败。我想知道该端口来自哪里,该配置不应该解析为默认地址并与正在运行的 Azurite 实例建立连接吗?

我的其他设置

local.settings.json
包括这些(忽略数据库连接字符串):

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_EXTENSION_VERSION": "~4",
  }
}

以下是运行该函数的完整日志,它失败并出现异常,指出无法从 Blob 存储秘密存储库读取。

FUNCTIONS_INPROC_NET8_ENABLED app setting is not enabled in local.settings.json
Selected inproc6 host.
Starting child process for inproc6 model host.
C:\Program Files\Microsoft\Azure Functions Core Tools\in-proc6\func.exe present
Started child process with ID: 19196
                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %
Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c5326276aae6b8a7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179
Found {ProjectName.csproj}. Using for user secrets file configuration.
[2024-12-03T18:00:30.447Z] Building host: version spec: ~4, startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '16eac4bd-8933-4a55-8ff5-c044ff92701f'
[2024-12-03T18:00:30.461Z] Reading host configuration file '..\bin\output\host.json'
[2024-12-03T18:00:30.465Z] Host configuration file read:
[2024-12-03T18:00:30.466Z] {
[2024-12-03T18:00:30.469Z]   "version": "2.0",
[2024-12-03T18:00:30.471Z]   "logging": {
[2024-12-03T18:00:30.472Z]     "applicationInsights": {
[2024-12-03T18:00:30.474Z]       "samplingSettings": {
[2024-12-03T18:00:30.476Z]         "isEnabled": true,
[2024-12-03T18:00:30.476Z]         "excludedTypes": "Request"
[2024-12-03T18:00:30.477Z]       }
[2024-12-03T18:00:30.477Z]     }
[2024-12-03T18:00:30.478Z]   }
[2024-12-03T18:00:30.478Z] }
[2024-12-03T18:00:30.500Z] Extension Bundle not loaded. Loading extensions from ..\bin\output\bin. BundleConfigured: False, PrecompiledFunctionApp: False, LegacyBundle: False, DotnetIsolatedApp: False, isLogicApp: False
[2024-12-03T18:00:30.503Z] Script Startup resetting load context with base path: '..bin\output\bin'.
[2024-12-03T18:00:30.511Z] Loading startup extension 'Startup'
[2024-12-03T18:00:30.593Z] Loaded extension 'Startup' (1.0.0.0)
[2024-12-03T18:00:30.612Z] Loading startup extension 'DurableTask'
[2024-12-03T18:00:30.615Z] Loaded extension 'DurableTask' (2.0.0.0)
[2024-12-03T18:00:30.617Z] Loading startup extension 'EventGrid'
[2024-12-03T18:00:30.621Z] Loaded extension 'EventGrid' (2.1.0.0)
[2024-12-03T18:00:30.648Z] Reading host configuration file '..\bin\output\host.json'
[2024-12-03T18:00:30.650Z] Host configuration file read:
[2024-12-03T18:00:30.651Z] {
[2024-12-03T18:00:30.654Z]   "version": "2.0",
[2024-12-03T18:00:30.657Z]   "logging": {
[2024-12-03T18:00:30.658Z]     "applicationInsights": {
[2024-12-03T18:00:30.660Z]       "samplingSettings": {
[2024-12-03T18:00:30.661Z]         "isEnabled": true,
[2024-12-03T18:00:30.663Z]         "excludedTypes": "Request"
[2024-12-03T18:00:30.665Z]       }
[2024-12-03T18:00:30.666Z]     }
[2024-12-03T18:00:30.667Z]   }
[2024-12-03T18:00:30.669Z] }
[2024-12-03T18:00:31.403Z] Using the default storage provider: AzureStorage.
[2024-12-03T18:00:32.665Z] Initializing Warmup Extension.
[2024-12-03T18:00:32.678Z] Resolved secret storage provider BlobStorageSecretsRepository
[2024-12-03T18:01:20.598Z] There was an error performing a read operation on the Blob Storage Secret Repository.
[2024-12-03T18:01:20.601Z] Azure.Core: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Http: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Sockets: No connection could be made because the target machine actively refused it.
[2024-12-03T18:01:20.671Z] A host error has occurred during startup operation '16eac4bd-8933-4a55-8ff5-c044ff92701f'.
[2024-12-03T18:01:20.674Z] Azure.Core: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Http: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Sockets: No connection could be made because the target machine actively refused it.

我尝试重新安装 VS、Azurite、Azure Core 工具,通过命令行运行该函数以隔离 VS,重新启动,清理 Azurite Temp 数据 - 到目前为止,这些都没有帮助。在

"AzureWebJobsSecretStorageType": "files"
上设置
local.settings.json
可以使该功能可访问(在启动过程中不会失败),但触发器最终会出现与上面相同的错误。

任何帮助将不胜感激,如果需要,我可以提供更多信息。预先感谢。

编辑:这是功能代码:


using Domain.Models.Shared.Transactions;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Stream.Transaction
{
    public class TransactionOrchestrationClient
    {
        [FunctionName(nameof(TransactionOrchestrationClient))]
        public async Task TransactionTrigger(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger logger)
        {
            try
            {
                var data = await req.Content.ReadAsAsync<Transaction>();
                var instanceId = await starter.StartNewAsync(nameof(TransactionOrchestrator), data);
                logger.LogInformation($"Started orchestration with ID = '{instanceId}'.");
                starter.CreateHttpManagementPayload(instanceId);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error occurred while executing {nameof(TransactionOrchestrationClient)}");
            }
        }
    }
}
.net azure azure-functions azure-storage-emulator azurite
1个回答
0
投票

默认情况下,存储模拟器服务在以下端口上运行,如MSDOC中所述。

使用以下命令记下使用端口 10000、10001、10002 的任务的 ProcessID:

netstat -p tcp -ano | findstr :<PORT>

示例:

netstat -p tcp -ano | findstr :10001

TCP    127.0.0.1:10001        0.0.0.0:0              LISTENING       10376(process_id)

通过以下命令使用服务的 PID 终止任务:

taskkill /PID <process_id> /F

示例:

taskkill /PID 10376 /F
SUCCESS: The process with PID 10376 has been terminated.

重启Azurite,请参考MSDOC命令:

"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Azure Storage Emulator\azurite.exe"

注意: 如果您的系统在公司代理下,您可能会遇到相同的错误。要解决此问题,请更改网络连接并再次测试功能。

我已经用你的代码测试了该功能:

public static class Function1
{
    [FunctionName("Function1")]
    public static async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "London"));
        return outputs;
    }

    [FunctionName(nameof(SayHello))]
    public static string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation("Saying hello to {name}.", name);
        return $"Hello {name}!";
    }

    [FunctionName("Function1_HttpStart")]
    public static async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        string instanceId = await starter.StartNewAsync("Function1", null);

        log.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

输出:

Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c53262XX7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179

[2024-12-04T08:31:56.803Z] Found C:\Users\uname\Source\Repos\FunctionApp\FunctionApp.csproj. Using for user secrets file configuration.
Functions:

        Function1_HttpStart: [GET,POST] http://localhost:7068/api/Function1_HttpStart

        Function1: orchestrationTrigger

        SayHello: activityTrigger

For detailed output, run func with --verbose flag.
[2024-12-04T08:32:05.712Z] Executing 'Function1_HttpStart' (Reason='This function was programmatically called via the host APIs.', Id=7ecac355-6aff-440f-95f1-ab992ecf5ac2)
[2024-12-04T08:32:09.010Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-12-04T08:32:09.103Z] Started orchestration with ID = '35d89e5d87c44b8bb47dc3d93ffcf767'.
[2024-12-04T08:32:09.150Z] Executed 'Function1_HttpStart' (Succeeded, Id=7ecac355-6aff-440f-95f1-ab992ecf5ac2, Duration=3466ms)
[2024-12-04T08:32:09.284Z] Executing 'Function1' (Reason='(null)', Id=cd0324d9-63ce-4a88-9f81-304763b959d7)
[2024-12-04T08:32:09.334Z] Executed 'Function1' (Succeeded, Id=cd0324d9-63ce-4a88-9f81-304763b959d7, Duration=55ms)
[2024-12-04T08:32:09.419Z] Executing 'SayHello' (Reason='(null)', Id=262653d8-a03e-4723-a43d-5242140090a7)
[2024-12-04T08:32:09.424Z] Saying hello to Tokyo.
[2024-12-04T08:32:09.427Z] Executed 'SayHello' (Succeeded, Id=262653d8-a03e-4723-a43d-5242140090a7, Duration=11ms)
[2024-12-04T08:32:09.528Z] Executing 'Function1' (Reason='(null)', Id=c07866a3-f609-4a08-9c1f-07fdda972c56)
[2024-12-04T08:32:09.536Z] Executed 'Function1' (Succeeded, Id=c07866a3-f609-4a08-9c1f-07fdda972c56, Duration=8ms)
[2024-12-04T08:32:09.574Z] Executing 'SayHello' (Reason='(null)', Id=3695b57e-a07d-4428-95d4-397954b84fd9)
[2024-12-04T08:32:09.578Z] Saying hello to Seattle.
[2024-12-04T08:32:09.580Z] Executed 'SayHello' (Succeeded, Id=3695b57e-a07d-4428-95d4-397954b84fd9, Duration=7ms)
[2024-12-04T08:32:09.619Z] Executing 'Function1' (Reason='(null)', Id=433593d2-f089-4b65-8397-801cd1f0f910)
[2024-12-04T08:32:09.624Z] Executed 'Function1' (Succeeded, Id=433593d2-f089-4b65-8397-801cd1f0f910, Duration=5ms)
[2024-12-04T08:32:09.651Z] Executing 'SayHello' (Reason='(null)', Id=a517ad04-532a-4bf6-8245-3a3598b014ba)
[2024-12-04T08:32:09.655Z] Saying hello to London.
[2024-12-04T08:32:09.657Z] Executed 'SayHello' (Succeeded, Id=a517ad04-532a-4bf6-8245-3a3598b014ba, Duration=6ms)
[2024-12-04T08:32:09.685Z] Executing 'Function1' (Reason='(null)', Id=ef0c8206-0633-46b1-aefa-a9661d18a59d)
[2024-12-04T08:32:09.695Z] Executed 'Function1' (Succeeded, Id=ef0c8206-0633-46b1-aefa-a9661d18a59d, Duration=9ms)
© www.soinside.com 2019 - 2024. All rights reserved.