【问题标题】:Message not added to Azurite Queue from Azure Function消息未从 Azure 函数添加到 Azurite 队列
【发布时间】:2022-01-23 01:05:37
【问题描述】:
【问题讨论】:
标签:
azure-functions
azure-queues
azure-storage-explorer
【解决方案1】:
我尝试通过以下步骤重现该问题:
- 在 Visual Studio 中创建了 Azure Functions(堆栈:.Net Core 3.1 - Http Trigger)。
- 通过 Nuget 包解决方案将这个包
Microsoft.Azure.WebJobs.Extensions.Storage 安装到项目中。
- 将输出队列绑定添加到任务静态方法中,如:
public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, [Queue("outqueue"), StorageAccount("AzureWebJobsStorage")] ICollector<string> msg, ILogger log)
添加了将函数URL中传递的参数写入输出队列的代码(在解析响应消息代码之前):
if (!string.IsNullOrEmpty(name))
{
// Add a message to the output collection.
msg.Add(string.Format("Name passed to the function: {0}", name));
}
现在完整的代码看起来是:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
-
在本地运行函数并将控制台中的函数 URL 连同以下参数复制到浏览器:
http://localhost:7071/api/Function1?name=HariKrishna
那么它应该在浏览器中显示为Hello, HariKrishna. This HTTP triggered function executed successfully.
-
转到 Storage Explorer > 展开 队列 并刷新它(右键单击queues 并单击刷新) 以查看函数运行时在函数运行时创建的队列并刷新 输出队列 还可以查看控制台输出、浏览器输出和队列中的消息以下屏幕截图中的消息: