gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:22:43 25 4
gpt4 key购买 nike

我编写了一个.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com