c# - Azure服务总线队列触发函数未被调用

标签 c# azure asp.net-core azure-functions azureservicebus

我编写了一个.Net Core 6代码,它将消息发送到服务总线队列,该队列进而触发一个函数(SB队列触发),我打算在其中进一步处理接收到的数据。尽管消息被发送到队列,但该函数不会被触发,消息最终会进入死信队列。

下面是我的函数代码:

using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using MyWebApp.Domain.Entities;
using MyWebApp.Domain.Repositories.Interface;

namespace MyFunctionApp
{
    public class Function1
    {
        private readonly ITaskRepository _taskRepository;

        public Function1(ITaskRepository taskRepository)
        {
            _taskRepository = taskRepository;
        }

        [FunctionName("Function1")]
        public async Task Run([ServiceBusTrigger("mysbqueue", Connection = "ServiceBusConnectionString")] TaskModel myQueueItem, ILogger log)
        {
            try
            {
                await _taskRepository.UpdateTask(myQueueItem);
                log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
            }
            catch(Exception ex)
            {
                log.LogError("An error occurred: " + ex.Message);
            }
        }
    }
}

请注意,我已在函数应用 local.settings.json 以及 Azure 门户中函数应用的配置部分中添加了 ServiceBusConnectionString但这没有帮助。我也无法在本地调试功能应用程序,正如它所说的 - 断点当前不会被命中。该文档尚未加载任何符号。

enter image description here

我在这里做错了什么?

最佳答案

如果消息将发送到死信队列,则该函数将被触发,但逻辑中存在一些错误,在经过一些尝试后,该函数将消息移动到死信队列。

我建议您通过 Application Insights/Log Stream 检测该功能并进行监控,以找出问题所在。

关于c# - Azure服务总线队列触发函数未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76531337/

相关文章:

c# - 如何使用 C# 在条件内使用带有字符串的 if 条件

c# - 从数据文件启动应用程序

azure - 使用 linkedtemplate 从 Keyvault 检索密码

asp.net - 如何在使用 docker 容器化的 asp.net Core 中的项目之间共享类定义

c# - 如何在 ASP.NET Core MVC 中获取 Url Referrer?

c# - 无法将内容从前端应用程序推送到数据库

c# - 如何通过反射获取 C# 属性名称作为字符串?

azure - Azure仪表板可以动态添加小部件吗?

javascript - 帮助将条目插入 Azure DB

asp.net - 如何在构建期间设置 appsettings.json 文件中的键值