none
Azure Event Hub Not Connecting RRS feed

  • Question

  • Hi,

    I am following this tutorial-  https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-python-get-started-send

    to send events to my event hub using Python

    The connection string of my Event Hub namespace is in the following format

    Endpoint=sb://<eventhubnamespacename>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<AcessKeyvalue>

    So, in the above mentioned tutorial, I have replaced tutorial I replaced 

    ADDRESS with
    "amqps://mynamespace.servicebus.windows.net/<myeventhub>"
    User="RootManageSharedAccessKey"
    KEY="<AcessKeyvalue>"

    But everytime , I run into errors with the line client.run

    'eventhub.pysdk-ANumber': All clients failed to start.

    azure.eventhub.common.EventHubError: Unable to open authentication session on connection b'EHSender-anumber-partition0'.
    Please confirm target hostname exists: b'eventhubnamespacename.servicebus.windows.net'

    I have even tried replacing amqps with sb (as is actually in the connection string but the same error)

    Where am I going wrong? 




    Monday, December 3, 2018 10:52 AM

Answers

All replies

  • Hi SaugatMukherjee

    Are you able to share a bit more complete implementation of your code? Here's an example to compare against: https://github.com/Azure/azure-event-hubs-python/blob/master/examples/send.py

    Hope this helps

    Tuesday, December 4, 2018 6:55 AM
    Moderator
  • Hi,

    Thanks for responding. As I mentioned in my question, I was following the sample code from Microsoft and that didn't work. 

    E.g this is the code snippet in Python

    from azure.eventhub import EventHubClient, Sender, EventData
    
    EventHubAddress="amqps://myeventhubnamespace.servicebus.windows.net/myeventhub"
    
    USER = "RootManageSharedAccessKey"
    KEY = "MyKeyValue"
    
    client = EventHubClient(EventHubAddress,debug=True,username=USER,password=KEY)
    sender = client.add_sender(partition="0")
    client.run()

    It seems like the ports 5671 and 5672 have to be opened on the org firewall. So, I have put in a request for that.

    I have also tried the same in C# by again following Microsoft's sample but with the extra line:

    ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; 

    I understand the above line would force the usage of the normal http port 80 and not 5671 and 5672(the support of which is unavailable in Python , at least till the end of this year), but even that does not work.

    namespace SampleSender
    {
        using System;
        using System.Text;
        using System.Threading.Tasks;
        using Microsoft.Azure.EventHubs;
        using System.Net;
        using Microsoft.ServiceBus;
        
    
        public class Program
        {
            private static EventHubClient eventHubClient;
            private const string EventHubConnectionString = "Endpoint=sb://myeventhubnamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=MyAccessKey";
            private const string EventHubName = "MyEventHubname";
    
            public static void Main(string[] args)
            {
                ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
                MainAsync(args).GetAwaiter().GetResult();
            }
    
            private static async Task MainAsync(string[] args)
            {
                // Creates an EventHubsConnectionStringBuilder object from the connection string, and sets the EntityPath.
                // Typically, the connection string should have the entity path in it, but for the sake of this simple scenario
                // we are using the connection string from the namespace.
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
                {
                    EntityPath = EventHubName
                };
    
                
    
                eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
                WebProxy proxyObject = new WebProxy("http://127.0.0.1:8888", true);
                proxyObject.UseDefaultCredentials = true;
                
                eventHubClient.WebProxy = proxyObject;
    
    
                await SendMessagesToEventHub(100);
    
                await eventHubClient.CloseAsync();
    
                Console.WriteLine("Press ENTER to exit.");
                Console.ReadLine();
            }
    
            // Creates an event hub client and sends 100 messages to the event hub.
            private static async Task SendMessagesToEventHub(int numMessagesToSend)
            {
                for (var i = 0; i < numMessagesToSend; i++)
                {
                    try
                    {
                        var message = $"Message {i}";
                        Console.WriteLine($"Sending message: {message}");
                        await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
                    }
    
                    await Task.Delay(10);
                }
    
                Console.WriteLine($"{numMessagesToSend} messages sent.");
            }
        }
    }


    Tuesday, December 4, 2018 1:51 PM
  • Just an update- this was solved by opening up ports 5671 and 5672
    Wednesday, February 6, 2019 11:33 AM
  • Hi SaugatMukherjee,

    I face a similar problem, Can you please help me how to convert the 'sb' endpoint into 'amqps'

    Following is my endpoint: sb://qa-stage.servicebus.windows.net/;SharedAccessKeyName=QA-PTT;SharedAccessKey=<secretkey>;EntityPath=qa-qaptt-loaddata

    I want to find out the these details from the endpoint:

    1) ADDRESS = "amqps://<converted URL>"
    2) USER = "<value>"
    3) KEY = "<value>"



    Monday, February 11, 2019 10:46 AM
  • Hi,

    You can get your answer if you read my posts above ;)

    Also, never post your "keys" in a public forum, they are supposed to be secret :D. If you see my post above, I replaced them with placeholders.

    If you know which is your event hub namespace and your event hub, then it would be

    amqps://youreventhubnamespace.servicebus.windows.net/nameofyoureventhub

    user: the shared access key name

    Key: Is the secret (which you have posted publicly ;) )

    for your case: 

    address: "amqps://qa-stage.servicebus.windows.net/qa-qaptt-loaddata"

    User: "QA-PTT"

    Key: "JoSWLQ0C8FJBObZ+UR5PPz/O2fo3g="



    Tuesday, February 12, 2019 8:37 PM
  • Pleaze, how to "open up" ports. Should I search in Linux command or with a socket in Python ?
    Tuesday, May 7, 2019 1:17 PM