如何创建连接来创建 - 队列项 - HTTP 触发器 - 本地 - Azurite - Azure 队列存储

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

我安装了 Azurite 并启动(假设命令是正确的。)

蓝铜矿--queueHost 127.0.0.1

我使用 Azure 存储资源管理器创建了一个输出队列

我想测试/使用这个功能

const { app, output } = require('@azure/functions');

const queueOutput = output.storageQueue({
    queueName: 'outqueue',
    connection: 'MyStorageConnectionAppSetting',
});

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraOutputs: [queueOutput],
    handler: async (request, context) => {
        const body = await request.text();
        context.extraOutputs.set(queueOutput, body);
        return { body: 'Created queue item.' };
    },
});

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cextensionv5&pivots=programming-语言-javascript

我不知道/理解的是“MyStorageConnectionAppSetting”。 (指定如何连接到 Azure 队列的应用设置或设置集合的名称。请参阅连接。)

错误

[2024-04-22T11:04:11.464Z] System.Private.CoreLib:异常 执行函数:Functions.httpTrigger1。 Microsoft.Azure.WebJobs.Extensions.Storage.Queues:存储帐户 连接字符串“AzureWebJobsMyStorageConnectionAppSetting”不 存在。确保它是已定义的应用程序设置。

创建 MyStorageConnectionAppSetting 时缺少的步骤是什么?任何提供步骤的参考文档都值得赞赏。

谢谢你

azure azure-functions azure-storage-queues
1个回答
0
投票

要解决该错误,请在

local.settings.json
中传递存储连接字符串。 local.settings.json:

"MyStorageConnectionAppSetting":"<Storage_Connection_String>"

我在我的环境中复制了相同的内容。

代码片段:

const { app, output } = require('@azure/functions');

const queueOutput = output.storageQueue({
    queueName: 'outqueue',
    connection: 'MyStorageConnectionAppSetting',
});

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraOutputs: [queueOutput],
    handler: async (request, context) => {
        const body = await request.text();
        context.extraOutputs.set(queueOutput, body);
        return { body: 'Created queue item.' };
    },
});

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "MyStorageConnectionAppSetting":"<Storage_Connection_String>"
  }
}
  • 在 Azure 存储帐户中创建了名为
    outqueue
    的队列。

在本地运行该函数:

C:\Users\uname\function>func start

Azure Functions Core Tools
Core Tools Version:       4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

[2024-04-22T13:17:40.044Z] Worker process started and initialized.

Functions:

        httpTrigger1: [GET,POST] http://localhost:7071/api/httpTrigger1

For detailed output, run func with --verbose flag.
[2024-04-22T13:17:53.133Z] Executing 'Functions.httpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=00ec97ec-a464-43af-acff-854c28b43711)
[2024-04-22T13:17:56.667Z] Executed 'Functions.httpTrigger1' (Succeeded, Id=00ec97ec-a464-43af-acff-854c28b43711, Duration=3631ms)

回复:

enter image description here

  • 队列项目已在
    Storage Account=>Queue=>outqueue
    中创建。

传送门:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.