无法从 Azure 函数将消息写入服务总线队列

Unable to write message to Service Bus Queue from Azure Function

我正在尝试按照文档从 Azure 函数 (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=csharp) 向 Azure 服务总线队列写入消息。

我从 HTTP 触发器的“文件 -> 新项目”开始并添加了绑定:

[FunctionName("Message")]
[return: ServiceBus("namequeue")]
public static async Task<string> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    string name = data?.name ?? "DefaultName";

    return name;
}

我的 host.json 和 local.settings.json 文件包含:

"extensions": {
    "serviceBus": {
        "prefetchCount": 100,
        "messageHandlerOptions": {
            "autoComplete": true,
            "maxConcurrentCalls": 32,
            "maxAutoRenewDuration": "00:05:00"
        },
        "sessionHandlerOptions": {
            "autoComplete": false,
            "messageWaitTimeout": "00:00:30",
            "maxAutoRenewDuration": "00:55:00",
            "maxConcurrentSessions": 16
        },
        "batchOptions": {
            "maxMessageCount": 1000,
            "operationTimeout": "00:01:00",
            "autoComplete": "true"
        }
    }
},
"Values": {
    "AzureWebJobsServiceBus": "Endpoint=<redacted>"
}

当 运行 在本地时,我收到超时异常(可能是公司防火墙)。

当部署到 Azure 时,我可以 POST 函数,得到 204 回复,但没有消息添加到队列中。

我想我错过了一个关键步骤,因为我在 Azure 门户中的 function.json 有:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-3.0.13",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "post"
      ],
      "authLevel": "anonymous",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/AppMapServiceBusCreate.dll",
  "entryPoint": "AppMapServiceBus.CreateMessageFunction.Run"
}

当我在门户中单击“集成”时,没有任何输出,添加一个会给我一条警告“为了查看可用功能模板的完整列表,您必须为您的应用程序设置扩展包。” .

我认为扩展包是非 .NET 代码,而事实上我通过 NuGet 添加了以下内容做了同样的事情?

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />

如果那是准确的,how/what 我要添加到 function.json 吗?

对于使用输出触发器写入服务总线的 Azure Functions,您需要将连接字符串添加为函数配置中的应用程序设置。 By default,预期的设置名称是 AzureWebJobsServiceBus: