0
votes

I’m working on Azure Event Hub. I have an issue when connecting to azure event hub when I’m connected to corpnet network. If I run the code without joining corpnet network it works fine. Telnet test against the event hub looks good when I’m connected to corpnet network.

Any idea how to resolve this?

Below is the code, error message and stack trace.

Code:

            public async Task SendDataAsync(CoffeeMachineData data)
            {
                EventData eventData = CreateEventData(data);
                await _eventHubClient.SendAsync(eventData);
            }



            private static EventData CreateEventData(CoffeeMachineData data)
            {
                var dataAsJson = JsonConvert.SerializeObject(data);
                var eventData = new EventData(Encoding.UTF8.GetBytes(dataAsJson));
                return eventData;
            }

Error Message:

            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

Stack Trace:

           at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
           at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
           at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
           at Microsoft.Azure.Amqp.Transport.TlsTransport.HandleOpenComplete(IAsyncResult result, Boolean syncComplete)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at Microsoft.Azure.Amqp.ExceptionDispatcher.Throw(Exception exception)
           at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result)
           at Microsoft.Azure.Amqp.AmqpObject.OpenAsyncResult.End(IAsyncResult result)
           at Microsoft.Azure.Amqp.AmqpObject.EndOpen(IAsyncResult result)
           at Microsoft.Azure.Amqp.Transport.TlsTransportInitiator.HandleTransportOpened(IAsyncResult result)
           at Microsoft.Azure.Amqp.Transport.TlsTransportInitiator.OnTransportOpened(IAsyncResult result)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.Azure.EventHubs.Amqp.AmqpEventHubClient.<CreateConnectionAsync>d__31.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.<OnCreateAsync>d__5.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.Singleton`1.<CreateValue>d__20.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__13.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
           at Microsoft.Azure.EventHubs.Amqp.AmqpEventDataSender.<CreateLinkAsync>d__12.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.<OnCreateAsync>d__5.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.Singleton`1.<CreateValue>d__20.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__13.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.Azure.EventHubs.Amqp.AmqpEventDataSender.<OnSendAsync>d__10.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at Microsoft.Azure.EventHubs.Amqp.AmqpEventDataSender.<OnSendAsync>d__10.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.Azure.EventHubs.EventHubClient.<SendAsync>d__19.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
2
How is your corpnet getting to Azure? Do you use a VPN or ExpressRoute? Are there any firewalls or web proxies you must go through to get to the Internet. If you are connected through ER make sure Microsoft Peering is enabled (public peering if it's a legacy circuit). See docs.microsoft.com/en-us/azure/expressroute/…Ken W MSFT
Thanks @ken-w-msft. I will be finding those information. But one more interesting point is I'm able to connect to Azure Functions, Cosmos DB or any other azure resources. Its only for Event Hubs I'm having issue. Is the connecting method to Azure resources is different for different resource type?Dheeraj
Azure Functions and Cosmos DB both use port 443, Event Hub can use 443, 5671 and 5672. The last two ports are not always open on outbound firewalls or host-based sec tools (e.g. McAffe ePO/HIPS). Tom Sun has more info in the answer below.Ken W MSFT
Do you have any update about this thread? If it is useful, you could mark it as an answer.Tom Sun - MSFT

2 Answers

3
votes

We found the solution for this. We had to use AmqpWebSockets while building the connection string of event hub.

        var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
        {
            EntityPath = entityName,
            TransportType = TransportType.AmqpWebSockets
        };
0
votes

Any idea how to resolve this?

please have a try to set the ConnectivityMode to https (443 port)

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https 

It seems that firewall restriction which blocks all traffic on ports 5671 and 5672. TCP port is used by default for transport operations.

We could get more information from AMQP 1.0 in Azure Service Bus and Event Hubs protocol guide.

If possible, you could have a try open the port 5671 and 5672.