从本地 Windows 10 盒子连接到 azure 服务总线失败
我有一个 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);
}
}
I have an HTTP trigger / Azure function that tries to write to a service bus. WHen I try to trigger locally via POSTMAN, this is the error I get in 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.
So I found this article: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-troubleshooting-guide
And I've tried to add a Firewall rule to open up everything incoming / outgoing to my specific ip address. To get the ip address I ran this command in 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
I added both an incoming and an outgoing FW rule on my local windows 10 development box. I added a "custom rule" that allows all program, all ports for that specific IP address.
Then I tried to telnet to my azure service bus but it blows up in my face: (tried telnet via ubuntu subsystem on windows 10)
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
Not sure what else to check.
Any tips would be appreciated.
EDIT 1
This is what my code looks like right now:
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(quot;WidgetsNotificationPOST method invoked");
var content = await new StreamReader(req.Body).ReadToEndAsync();
log.LogInformation(quot;Received following payload: {content}");
var widgetsNotification= JsonConvert.DeserializeObject<WidgetsNotification>(content);
await outputQueue.AddAsync(widgetsNotification);
var response = new {widgetsNotification, QueuedResult=true};
return new OkObjectResult(response);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的网络环境似乎不允许端口 5671 和 5672 的流量。这通常可以通过将
ServiceBusClient
配置为使用使用端口 443(默认 HTTPS 端口)的 Web 套接字传输来解决:对于 Azure Functions配置服务总线触发器和绑定,使用 v5.0+ 时可以在
host.json
中指定传输Microsoft.Azure.WebJobs.Extensions.ServiceBus
包。It appears that your network environment is not allowing traffic for ports 5671 and 5672. This is often resolved by configuring the
ServiceBusClient
to use the web sockets transport which uses port 443 (default HTTPS port):For Azure Functions configuration of the Service Bus trigger and bindings, the transport can be specified in
host.json
when using v5.0+ of theMicrosoft.Azure.WebJobs.Extensions.ServiceBus
package.