我想从Azure Function写入服务总线队列。但是ServiceBus配置不起作用。

我有以下依赖项:

  • Microsoft.Azure.WebJobs.ServiceBus 3.0.0-beta5
  • Microsoft.NET.Sdk.Functions 1.0.13

  • 谁能帮我连接到服务总线吗?
    using System.IO;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Extensions.Http;
    using Microsoft.AspNetCore.Http;
    using Newtonsoft.Json;
    using Microsoft.Azure.WebJobs.Host;
    
    namespace HttpTrigger
    {
        public static class RegisterDevice
        {
            [FunctionName("RegisterDevice")]
            public static IActionResult Run(
                [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
                [ServiceBus("deviceupdates", Connection = "ServiceBusConnection")] ICollector<string> outputSbMsg,
                TraceWriter log)
            {
    
            log.Info("C# HTTP trigger function processed a request.");
    
            string name = req.Query["name"];
    
            string requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;
    
            outputSbMsg.Add(name);
    
            return name != null
                ? (ActionResult)new OkObjectResult($"Hello, {name}")
                 : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
        }
    }
    

    }

    local.settings.json(更新)
    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
        "ServiceBusConnection":"SecretConnectionString"
      }
    }
    

    最佳答案

    您的代码看起来不错。

    将您的QueueConnectionString放在Values下,而不是ConnectionStrings下。

    09-03 19:04