You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HTTP触发Azure函数向Service Bus队列写消息失败求助

我的Azure函数无法将消息写入Service Bus队列,求排查问题

我正在开发一个Azure函数,功能是接收HTTP POST请求、读取请求数据并将其写入Service Bus队列。本地调试时,用PostMan发送请求后,能看到数据被正常提取,函数无错误返回,也能看到请求到达队列的记录,但没有实际消息写入队列。我试过Stack Overflow上的多种代码修改方案,都没有效果,麻烦帮我排查哪里操作有误。

我的函数代码

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.Functions.Worker;

namespace foo
{
    public static class foo
    {
        [FunctionName(nameof(bar))]
        [ServiceBusOutput("myBus", Connection = "ServiceBusConnection")]
        public static async Task<IActionResult> bar(
            [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("processed a request.");
            string tld;
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            Models.foo data = JsonConvert.DeserializeObject<Models.foo>(requestBody);
            theThing = data.Name ?? "";

            if (string.IsNullOrEmpty(theThing))
            {
                log.LogError("No data passed to function. Aborting");
                throw new Exception("a message");
            }
            return new OkObjectResult(theThing);
        }
    }
}

配置信息

local.settings.json 配置项

"ServiceBusConnection__fullyQualifiedNamespace": "myfunctionnamespace.servicebus.windows.net",

我已在Function App应用设置中同步配置该值,并且通过IAM为函数授予了Service Bus数据读取者和发送者权限。

已安装的NuGet包

  • Microsoft.Azure.Functions.Worker.Extensions.ServiceBus (5.14.1)
  • Microsoft.Azure.WebJobs.Extensions.ServiceBus (5.13.4)
  • Microsoft.NET.Sdk.Functions (4.2.0)

生成的function.json文件

我怀疑这个文件存在问题:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-4.2.0",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "post"
      ],
      "authLevel": "function",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/foo.dll",
  "entryPoint": "foo.foo.bar"
}

内容的提问来源于stack exchange,提问作者Jay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:25:21