gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:15:14 27 4
gpt4 key购买 nike

我创建了一个通过 Http 触发的函数应用程序。函数应用应将消息发布到 Azure 服务总线主题。但是,由于某种原因,消息没有发布到服务总线主题中。函数应用程序已成功触发,我可以从 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 .

enter image description here

最佳答案

从我们这边重现后发现,将Route更改为null后,我们能够在服务总线中接收消息。下面是对我有用的代码。

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;
}
}
}

结果:

enter image description here

enter image description here

enter image description here

关于c# - Azure函数不向服务总线主题发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71640302/

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