gpt4 book ai didi

azure - 通过 Visual Studio 在 Azure Functions 中使用 ServiceBus

转载 作者:行者123 更新时间:2023-12-01 08:31:02 26 4
gpt4 key购买 nike

我想从 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下。

关于azure - 通过 Visual Studio 在 Azure Functions 中使用 ServiceBus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49813652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com