Connecting to azure service bus from local windows 10 box failing - azure

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($"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);
}
}

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

Related

Microsoft.Azure.Storage.Common: No connection could be made because t he target machine actively refused it

*[2022-07-21T11:29:11.318Z] The listener for function 'Functions.BlobTriggerFunction' was unable to start.
[2022-07-21T11:29:11.319Z] The listener for function 'Functions.BlobTriggerFunction' was unable to start. Microsoft.Azure.Storage.Common: No connection could be made because the target
machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because t
he target machine actively refused it.
[2022-07-21T11:29:12.311Z] An unhandled exception has occurred. Host is shutting down.
[2022-07-21T11:29:12.312Z] Microsoft.Azure.Storage.Common: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made beca
use the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.*
I have created azure function blob trigger using IntelliJ IDEA Java, after this i am trying to run it locally then it is giving me this error.
public class BlobTriggerFunction {
/**
* This function will be invoked when a new or updated blob is detected at the specified path.
* The blob contents are provided as input to this function.
*/
#FunctionName("BlobTriggerFunction")
#StorageAccount("AzureWebJobsStorage")
public void run(
#BlobTrigger(name = "content", path = "ys01/{name}", dataType = "binary",
connection = "AzureWebJobsStorage") byte[] content,
#BindingName("name") String name,
final ExecutionContext context
) {
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + name + "\n Size: "
+ content.length + " Bytes");
System.out.println("logger ");
}
}
No connection could be made because the target machine actively refused it.
This can be due to your port is already using by some other function or process so change to different port and check.
Also make sure your local storage emulator is running. If not, start the Azure storage emulator.
Refer to one of the workarounds given by Mayank Bargali in Q&A Forum.

Azure Cosmos DB: 503 Service Unavailable

While connecting from my code outside of the company network, the Cosmos DB connection works just fine. But from the company network, it throws a 503 ServiceUnavailable status code. What are the possible issues?
Based on the comments:
System.Exception: 'Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: ServiceUnavailable (503); Substatus: 0;
ActivityId: ;
Reason: (The request failed because the client was unable to establish connections to 4 endpoints across 1 regions. Please check for client resource starvation issues and verify connectivity between client and server.
Normally, if you take that exception and store or view the ToString(), it will show you more information. But from the message itself, it means the client tried to connect to all known endpoints available and failed.
This normally means there is either something on the network blocking your request or the machine executing this code is completely overloaded (CPU at 100% or port exhaustion) and cannot process any request.
If this is consistently failing for all operations, check that your network has the correct port range open:
By default, the SDK works in Direct mode, so check that ports in the 10000 through 20000 range are open and available. If you have private endpoint enabled, the range is 0 to 65535.
As #GauravMantri mentioned, you can change to Gateway mode also if the network is restricted:
string connectionString = "<your-account-connection-string>";
CosmosClient client = new CosmosClient(connectionString,
new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway
});

Azure Point to Site VPN with Basic SKU not working on Windows 10 (ErrorCode = 720 ErrorSource = RAS)

I am trying to connect to Azure vNET Gateway and I am not having success. It ends with ErrorCode = 720 ErrorSource = RAS. Anyone experienced this issue before for the following scenario?
Azure vNET Gateway configured with Basic SKU.
VpnStrategy is SSTP for Windows 10
Authentication: Client certificate (self signed)
Both the root and client certificates are in current user personal store. They are resolved ok.
Root cert is stored in trusted root path of current user
Root cert is saved in Azure vpn gateway user configuration without line breaks
Don't wish to create other SKU to save $$ on poc
Deleted all the WAN Miniport adapters and rebooted the machine with no success. They get recreated automatically
I can't share certificates (root or client) in this forum since I am revealing the vpn gateway endpoint in the logs (for security reason)
Event logs from local machine in the order of execution:
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM has started dialing a Connection Manager connection using a per-user connection profile named az-aks-vnet-v2. The connection settings are:
Dial-in User = P2SDemoClientCert
VpnStrategy = SSTP
DataEncryption = Require
PrerequisiteEntry =
AutoLogon = No
UseRasCredentials = Yes
Authentication Type = EAP <Microsoft: Smart Card or other certificate>
Ipv4DefaultGateway = No
Ipv4AddressAssignment = By Server
Ipv4DNSServerAssignment = By Server
Ipv6DefaultGateway = Yes
Ipv6AddressAssignment = By Server
Ipv6DNSServerAssignment = By Server
IpDnsFlags =
IpNBTEnabled = Yes
UseFlags = Private Connection
ConnectOnWinlogon = No.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM is trying to establish a link to the Remote Access Server for the connection named az-aks-vnet-v2 using the following device:
Server address/Phone Number = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
Device = WAN Miniport (SSTP)
Port = VPN1-1
MediaType = VPN.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM has successfully established a link to the Remote Access Server using the following device:
Server address/Phone Number = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
Device = WAN Miniport (SSTP)
Port = VPN1-1
MediaType = VPN.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The link to the Remote Access Server has been established by user SYSTEM.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM dialed a connection named az-aks-vnet-v2 which has failed. The error code returned on failure is 720.
VPN logs:
******************************************************************
Operating System : Windows NT 10.0
Dialer Version : 7.2.18362.1
Connection Name : az-aks-vnet-v2
All Users/Single User : Single User
Start Date/Time : 6/22/2020, 10:31:31
******************************************************************
Module Name, Time, Log ID, Log Item Name, Other Info
For Connection Type, 0=dial-up, 1=VPN, 2=VPN over dial-up
******************************************************************
[cmdial32] 10:31:31 03 Pre-Init Event CallingProcess = C:\WINDOWS\system32\rasautou.exe
[cmdial32] 10:31:40 04 Pre-Connect Event ConnectionType = 1
[cmdial32] 10:31:40 06 Pre-Tunnel Event UserName = P2SDemoClientCert Domain = DUNSetting = b80c0077-e69d-4f0c-8f50-baa0c7a6e23e Tunnel DeviceName = TunnelAddress = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
[cmdial32] 10:31:42 21 On-Error Event ErrorCode = 720 ErrorSource = RAS
Thanks in advance for the help.
The problem is resolved, I just needed a break from computer and take a long evening walk! This is what I did to fix the problem-
Open Device Manager
Go to Network Adapters
Uninstall all the adapters name starts with "WAN Miniport". Repeat the step for every “WAN Miniport driver” installed
I didn't reboot the machine.
Right click “Network adapters” and select “Scan for hardware changes”
All of the WAN Miniport adapters will reappear immediately
I was able to connect to the VPN Gateway after the above steps and connect to VM with private ip.
Thanks to svenvdveen for the solution with the exception of no reboot. I followed the same instruction (twice) before and I rebooted the machine but didn't have luck!
I ran into a similar issue with Azure Basic Gateway.
For anyone reading this, I suggest you start by simply uninstalling the Wan Miniport (Ikev2). Then try to connect to your VPN again. It worked in my case :).
(Windows 11)

FTP is not connecting through Azure webjobs

I have deployed console application as webjobs on Azure which is getting data from ftp server but when run the console application on local it works fine but when deploy it on Azure it throws exception IO Exception while connecting to FTP server.
I deployed a webjob to get data from kudu via FTP, it worked fine on local but couldn't get data on the azure as same as you.
public static void main(String[] args) {
FTPClient client = new FTPClient();
try {
client.connect("url");
client.login("username", "password");
if (client.isConnected()) {
// Obtain a list of filenames in the current working
// directory. When no file found an empty array will
// be returned.
String[] names = client.listNames();
for (String name : names) {
System.out.println("Name = " + name);
}
FTPFile[] ftpFiles = client.listFiles();
for (FTPFile ftpFile : ftpFiles) {
// Check if FTPFile is a regular file
if (ftpFile.getType() == FTPFile.FILE_TYPE) {
System.out.printf("FTPFile: %s; %s%n",
ftpFile.getName(),
FileUtils.byteCountToDisplaySize(ftpFile.getSize()));
}
}
}
client.logout();
} `
Per my experience, it's due to the Kudu Network restriction. Webjob runs in its sandbox, the only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports.
Applications can create a socket which can listen for connections from within the sandbox. For example, two processes within the same app may communicate with one another via TCP sockets; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail. Here is the reference.
If you still have questions , please let me know.

Cannot get simple SignalR Azure worker role to work

I am trying to get a simple WebSocket server going using SignalR, OWIN and Azure Worker Roles.
WorkerRole.cs:
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
string url = "http://" + RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyEndpoint"].IPEndpoint;
using (WebApp.Start<Startup>(url))
{
Trace.WriteLine(String.Format("Server running on {0}", url));
}
while (true)
{
}
}
/* ... */
}
Startup.cs:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
MyHub.cs:
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
The Endpoint "MyEndpoint" is defined in the Service as http, public and private port 5001.
After starting the service, it shows up under Azure Compute Emulator as running on 5001. However, if I try to connect to ws://127.0.0.1:5001/signalr (or just ws://127.0.0.1:5001) there is no response. I am using two different web socket clients for this purpose (both are Chrome plugins and they both worked fine using other WebSocket servers).
Questions:
1) Is there anything obviously wrong with my setup?
2) Do I need to use the SignalR JS client libraries to connect to the SignalR server, or should any vanilla client implementing the WebSocket protocol be able to connect?
I know this is a bit of an old post but just in case someone needs it...
1) There are two problems you need to address.
First of all, Start method in:
using (WebApp.Start<Startup>(url))
{
Trace.WriteLine(String.Format("Server running on {0}", url));
}
returns an IDisposable (hence the using(...){} block) means it is immediately disposed after creation since execution continues right passed Trace.Writeline(...) without pause.
It's also a bit tricky running these things under the Azure Compute Emulator for a few reasons, mainly because it remaps ports to avoid collisions. If you open up a command prompt and run
netstat -a
you'll find that you have open ports (listening) looking something like this (in my case I'm using port 81):
TCP 127.0.0.1:82 MyComputer:0 LISTENING
TCP 127.0.0.3:81 MyComputer:0 LISTENING
In the general console ouput of Visual Studio, you'll also most likely see something like
"Windows Azure Tools: Warning: Remapping private port 81 to 82 in role 'MyRoleThingy' to avoid conflict during emulation."
This all means that in order to connect to the server you're hosting using your worker role, you'll have to connect to port 82 instead of 81 (probably 5002 in your case).
2) If you implement the protocol, anything should work I think. Managing an initial connection on the port should always work.

Resources