gpt4 book ai didi

azure - 从本地 Windows 10 盒子连接到 azure 服务总线失败

转载 作者:行者123 更新时间:2023-12-03 05:22:13 24 4
gpt4 key购买 nike

我有一个 HTTP 触发器/Azure 函数,它尝试写入服务总线。当我尝试通过 POSTMAN 本地触发时,这是我在 VSCODE 中遇到的错误:

[2022-02-25T17:47:27.426Z] Executed 'mytestmethod' (Failed, Id=61291e4d-92de-4306-93ba-c0902dbaae3b, Duration=96242ms)
[2022-02-25T17:47:27.428Z] System.Private.CoreLib: Exception while executing function: O3mWorkspaceNotifications. System.Private.CoreLib: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ErrorCode: TimedOut (ServiceCommunicationProblem). System.Private.CoreLib: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

所以我找到了这篇文章:https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-troubleshooting-guide

我尝试添加防火墙规则来打开所有传入/传出到我的特定 IP 地址的内容。为了获取 IP 地址,我在 powershell 中运行了以下命令:

PS C:\Users\me\.azure> tnc myresourcegroup-bus.servicebus.windows.net -port 5671
WARNING: TCP connect to (111.11.1.11 : 5671) failed
WARNING: Ping to 111.11.11.11 failed with status: TimedOut

ComputerName : myresourcegroup-bus.servicebus.windows.net
RemoteAddress : 111.11.11.11
RemotePort : 5671
InterfaceAlias : Ethernet
SourceAddress : 10.111.11.111
PingSucceeded : False
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded : False

我在本地 Windows 10 开发盒上添加了传入和传出固件规则。我添加了一条“自定义规则”,允许该特定 IP 地址的所有程序、所有端口。

然后我尝试 telnet 到我的 azure 服务总线,但它在我面前爆炸了:(尝试通过 Windows 10 上的 ubuntu 子系统进行 telnet)

admin@CAMXL0332ZPD:/mnt/c/Users/me$ telnet 111.11.11.11 5671
Trying 111.11.11.11...
telnet: Unable to connect to remote host: Resource temporarily unavailable

不确定还需要检查什么。任何提示将不胜感激。

编辑 1

这就是我的代码现在的样子:

public class mywidgetsclass {
[FunctionName("widgetsNotifications")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "mywidgets/sbnotification")] HttpRequest req,
[ServiceBus("widgets", ServiceBusEntityType.Queue, Connection = "WidgetsServiceBus")] IAsyncCollector<WidgetsNotification> outputQueue,
ILogger log)
{
log.LogInformation($"WidgetsNotificationPOST method invoked");

var content = await new StreamReader(req.Body).ReadToEndAsync();
log.LogInformation($"Received following payload: {content}");

var widgetsNotification= JsonConvert.DeserializeObject<WidgetsNotification>(content);

await outputQueue.AddAsync(widgetsNotification);
var response = new {widgetsNotification, QueuedResult=true};
return new OkObjectResult(response);
}


}

最佳答案

您的网络环境似乎不允许端口 5671 和 5672 的流量。这通常可以通过将 ServiceBusClient 配置为使用使用端口 443(默认 HTTPS 端口)的 Web 套接字传输来解决:

var options = new ServiceBusClientOptions
{
TransportType = ServiceBusTransportType.AmqpWebSockets
};

var client = new ServiceBusClient("<< CONNECTION STRING >>", options);

对于服务总线触发器和绑定(bind)的 Azure Functions 配置,使用 Microsoft.Azure.WebJobs.Extensions v5.0+ 时,可以在 host.json 中指定传输。 ServiceBus 包。

{
"extensions": {
"serviceBus": {
"transportType" : "amqpWebSockets"
}
}

关于azure - 从本地 Windows 10 盒子连接到 azure 服务总线失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71269918/

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