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://docs.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($"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);
}
}
CodePudding user response:
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):
var options = new ServiceBusClientOptions
{
TransportType = ServiceBusTransportType.AmqpWebSockets
};
var client = new ServiceBusClient("<< CONNECTION STRING >>", options);
For Azure Functions configuration of the Service Bus trigger and bindings, the transport can be specified in host.json
when using v5.0 of the Microsoft.Azure.WebJobs.Extensions.ServiceBus
package.
{
"extensions": {
"serviceBus": {
"transportType" : "amqpWebSockets"
}
}