【问题标题】:Cannot run Azure Function with service bus trigger无法使用服务总线触发器运行 Azure 函数
【发布时间】:2021-01-07 12:40:21
【问题描述】:

我使用服务总线触发器创建了一个 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}");

        }

    }

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

【问题讨论】:

    标签: visual-studio azure-functions azureservicebus


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2019-05-01
      • 2021-11-21
      • 2023-02-14
      • 2022-08-17
      • 2020-05-03
      • 1970-01-01
      相关资源
      最近更新 更多