无法使用服务总线触发器 运行 Azure Function

Cannot run Azure Function with service bus trigger

我创建了一个带有服务总线触发器的 azure 函数,当我尝试 运行 该函数时出现此错误:

[2021-01-07T12:32:43.565Z] A host error has occurred during startup operation '4f45a03c-9302-43c6-8c54-e6555bc0f562'.
[2021-01-07T12:32:43.566Z] System.Private.Uri: Value cannot be null. (Parameter 'uriString').

我已经为开发存储设置了 local.settings.json 文件

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

并且我在使用 AzureWebJobsStorage 的函数中有连接字符串

public static class ProcessAS2ExchangeInboundExceptions
    {
        [FunctionName("ProcessAS2ExchangeInboundExceptions")]
        public static void Run(
            [ServiceBusTrigger("as2-exchange-inbound-topic", "exceptions", Connection = "AzureWebJobsStorage")] string myQueueItem,
            ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

        }

    }

我不确定是什么问题。任何帮助将不胜感激。

根据您的配置,AzureWebJobsStorage 表示 Azure Storage 而不是 Azure Service Bus 的连接字符串。因此,您应该定义一个新配置以连接到具有主题和订阅名称的 Azure Service Bus 实例(确保 Azure Service Bus 的实例在 Azure 中启动)或使用 QueueTrigger用于 Azure 存储的队列名称。

更新以下代码以表示 QueueTrigger

public static class ProcessAS2ExchangeInboundExceptions
{
    [FunctionName("ProcessAS2ExchangeInboundExceptions")]
    public static void Run(
        [QueueTrigger("as2-exchange-inbound-queue", Connection = "AzureWebJobsStorage")] string myQueueItem,
        ILogger log)
    {
        log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    }

}

队列触发器 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=csharp

Azure 服务总线触发器 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp