Azure 函数不向服务总线主题发送消息

Azure function not sending message to Service Bus Topic

我创建了一个通过 Http 触发的函数应用程序。函数应用应向 Azure 服务总线主题发布消息。但是,由于某种原因,消息没有发布到服务总线主题中。功能应用程序已成功触发,我能够 post 来自 Postman 的消息并收到成功的 200 OK 响应,没有任何错误。我不确定我在这里做错了什么。下面是我的代码。

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;

namespace Extensions
{
    public class HttpInputServiceBusOutput
    {
        [FunctionName("MessageProcessorFunction")]
        [return: ServiceBus("myTopic", Connection = "ServiceBusConnectionString")]
            public async Task<string> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = "sms")] HttpRequest req,
        ILogger log)
            {
                log.LogInformation("HTTP trigger function processed a request.");

                return "hello World";
            }
    }
}

Local.Settings.Json 文件

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "ServiceBusConnectionString": "Endpoint=sb://DDXXXXXXXXXX.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=ghg...................",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

请注意,我使用的是.Net core 3.1 版本框架。因此,我根据 Microsoft documentation.

安装了 Microsoft.azure.webjobs.extensions.servicebus 版本 5.3.0 而不是 Microsoft.Azure.Functions.Worker.Extensions.ServiceBus

从我们这边重现后发现把Route改成null后,我们可以在service bus中接收到消息了。以下是对我有用的代码。

using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace FunctionApp21
{
    public static class Function1
    {
        [FunctionName("Function1")]
        [return: ServiceBus("myqueue", Connection = "ServiceBusConnection")]
        public static async Task<string> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, 
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            return name;
        }
    }
}

结果: