我目前正在尝试使用服务总线触发器部署 Visual Studio 为 azure 函数创建的最基本代码。在本地工作正常,但当我将其部署到 azure 时,它似乎没有执行任何操作,如果我尝试手动执行它,则会收到以下错误:
2024-11-15T21:35:52Z [Information] Received HTTP response headers after 102.8069ms - 200
2024-11-15T21:35:52Z [Information] End processing HTTP request after 111.4159ms - 200
2024-11-15T21:35:52Z [Information] Call failed with gRPC error status. Status code: 'FailedPrecondition', Message: 'LockToken 00000000-0000-0000-0000-000000000000 not found.'.
2024-11-15T21:35:52Z [Error] Function 'FunctionSB', Invocation id 'c8144425-6892-40fc-a415-7f235d053743': An exception was thrown by the invocation.
我通过在环境变量 -> 连接字符串中声明它来使用此变量,如下图所示。
正如我所说,代码是基本代码:
[Function(nameof(FunctionSB))]
public async Task Run(
[ServiceBusTrigger("visionsystemmessages")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
string content = message.Body.ToString();
// Complete the message
await messageActions.CompleteMessageAsync(message);
Console.WriteLine("Success start");
}
我错过了什么吗?如果我没有提供足够的信息,请问我
该问题与 Azure Function App 设置中的错误配置或服务总线命名空间中的权限有关。
部署后,请确保在函数应用 > 环境变量 > 应用设置中添加服务总线队列连接字符串,如下所示。
"ServiceBusQueue": "<queueconnestring>"
现在向服务总线队列发送消息,如下所示。
一段时间后,您可以直接在函数应用程序的调用部分看到日志,如下所示。
代码:
using System;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace FunctionApp3
{
public class Function1
{
private readonly ILogger<Function1> _logger;
public Function1(ILogger<Function1> logger)
{
_logger = logger;
}
[Function(nameof(Function1))]
public async Task Run(
[ServiceBusTrigger("kamqueue", Connection = "ServiceBusQueue")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
string content = message.Body.ToString();
await messageActions.CompleteMessageAsync(message);
Console.WriteLine("Success start");
}
}
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"ServiceBusQueue": "<queueconnestring>"
}
}