C# 服务总线队列触发器永远不会被触发
C# Service Bus Queue trigger never gets triggered
我创建了一个非常简单的 .net core 3.1 函数项目,其中包含一个应该基于服务总线队列触发的函数。
代码如下所示:
[FunctionName("PublishImage")]
public static async Task Run(
[QueueTrigger("publishimage")]string message,
ILogger log)
{
log.LogInformation($"Started to publish image: {message}");
}
当我在本地启动该函数时,我看到他找到了该函数并且我没有得到任何异常。
然后当我向队列发送消息时。它不会被触发。在 Azure 中,我看到队列中现在有 4 条消息,无论我做什么,它都不会被触发,在本地看不到任何异常,如果我尝试在 Azure 中 运行 它启用了应用程序洞察力,我不会查看任何异常或任何信息。同样打开日志记录不会提供任何信息。
我的 host.json 现在看起来像这样:
{
"version": "2.0",
"functionTimeout": "04:00:00",
"extensions": {
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout": "00:00:30",
"batchSize": 16,
"maxDequeueCount": 5,
"newBatchThreshold": 8
}
}
}
- Microsoft.NET.Sdk.Functions 3.0.7 已安装。
- Azure 中的运行时间是 ~3
- 已设置并验证应用程序设置 AzureWebJobsServiceBus
我找到了解决办法。我正在使用服务总线队列。因此我不应该使用 QueueTrigger 而应该使用 ServiceBusTrigger。将代码更改为以下解决了问题:
[FunctionName("PublishImage")]
public static async Task Run(
[ServiceBusTrigger("publishimage")]string message,
ILogger log)
{
log.LogInformation($"Started to publish image: {message}");
}
是的,您混淆了 Azure 服务总线和 Azure 存储队列。 QueueTrigger 用于存储队列,ServiceBusTrigger 用于服务总线。
我创建了一个非常简单的 .net core 3.1 函数项目,其中包含一个应该基于服务总线队列触发的函数。
代码如下所示:
[FunctionName("PublishImage")]
public static async Task Run(
[QueueTrigger("publishimage")]string message,
ILogger log)
{
log.LogInformation($"Started to publish image: {message}");
}
当我在本地启动该函数时,我看到他找到了该函数并且我没有得到任何异常。
然后当我向队列发送消息时。它不会被触发。在 Azure 中,我看到队列中现在有 4 条消息,无论我做什么,它都不会被触发,在本地看不到任何异常,如果我尝试在 Azure 中 运行 它启用了应用程序洞察力,我不会查看任何异常或任何信息。同样打开日志记录不会提供任何信息。
我的 host.json 现在看起来像这样:
{
"version": "2.0",
"functionTimeout": "04:00:00",
"extensions": {
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout": "00:00:30",
"batchSize": 16,
"maxDequeueCount": 5,
"newBatchThreshold": 8
}
}
}
- Microsoft.NET.Sdk.Functions 3.0.7 已安装。
- Azure 中的运行时间是 ~3
- 已设置并验证应用程序设置 AzureWebJobsServiceBus
我找到了解决办法。我正在使用服务总线队列。因此我不应该使用 QueueTrigger 而应该使用 ServiceBusTrigger。将代码更改为以下解决了问题:
[FunctionName("PublishImage")]
public static async Task Run(
[ServiceBusTrigger("publishimage")]string message,
ILogger log)
{
log.LogInformation($"Started to publish image: {message}");
}
是的,您混淆了 Azure 服务总线和 Azure 存储队列。 QueueTrigger 用于存储队列,ServiceBusTrigger 用于服务总线。