【发布时间】:2021-10-30 10:16:15
【问题描述】:
我正在尝试设置由 Azure 存储队列中的新消息触发的 Azure 函数。我有如下代码设置将消息发送到队列:
QueueClient queue = new(connectionString, queueName);
await queue.SendMessageAsync(message);
这部分工作正常。当我传入 connectionString、queueName 和 message 时,我可以看到该消息位于门户上的 Queue 中。
这是我无法理解的部分。我使用 Azure 存储队列模板设置了一个 Azure 函数,它引用的队列与 queueName 相同。但是,将消息添加到队列时,Azure 函数不会记录任何内容。据我了解,Azure 函数应该由添加到它指向它的队列中的消息触发,并且它应该记录该消息。我尝试了 .NET Core 3.1 In Process 和 .NET 5 隔离进程。我不确定我在这里缺少什么,或者我是否误解了某些东西。这是 Azure 函数 (.NET 5) 的代码。
[Function("QueueTrigger1")]
public static void Run([QueueTrigger("myqueue-items", Connection = "something_STORAGE")] string myQueueItem, FunctionContext context)
{
var logger = context.GetLogger("QueueTrigger1");
logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
这是程序.cs
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
这是host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}
【问题讨论】:
-
贴出azure函数代码+startup/program.cs(用于NET 5隔离)和host.json
-
@ThiagoCustodio 我添加了 .NET 5 函数的代码。这是我按照 Microsoft Docs 上的教程得到的。
-
对我来说一切正常,只要确保 local.settings.json 有一个有效的 something_STORAGE 条目:docs.microsoft.com/en-us/azure/azure-functions/…
-
@Stefan 您在 azure 门户中看到您的函数应用程序的任何“通知”吗?通常在那里报告缺少/不正确的连接字符串。您是否有一个名为
something_STORAGE的配置 AppSettings 具有连接字符串值? -
@Shyju 这是问题所在,我没有意识到 Azure 中没有使用 local.settings.json。我将 Connection 值更改为 Azure 门户中的值,它可以正常工作。
标签: c# azure .net-core azure-functions azure-storage-queues