Azure event hub : System.Net.Sockets.SocketException: 'No such host is known'

SAC_535 36 Reputation points
2022-07-26T07:07:12.723+00:00

Getting error : System.Net.Sockets.SocketException: 'No such host is known' while connecting to Azure event hub from .Net console app to event hub

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
568 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruno Lucas 4,411 Reputation points MVP
    2022-07-28T05:38:50.513+00:00

    Hi @SAC_535

    I follow that tutorial and worked just fine.
    I've committed my code here : https://github.com/blucas2016/SampleEventHubMessageSend

    You can clone and add your azure hub policy connection string.

    225632-image.png

    (1) is the connection string from the hub policy, not the hub namespace (https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string)

    225641-image.png

    (2) is the hub name

    Once you run you should see this:

    225490-image.png

    Receiver is the same this for (1)

    225676-image.png

    For (2) you need to create storage container:
    https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send#create-an-azure-storage-and-a-blob-container

    Run the "SampleEventHubMessageSend" first so you have messages in the hub before running "SampleEventHubMessageReceive"

    225627-image.png

    Please don't forget to click on "Accept Answer" or the vote button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer.


  2. Bruno Lucas 4,411 Reputation points MVP
    2022-07-28T23:34:04.007+00:00

    Hi @SAC_535

    You said you have define namespace, event hub and subscription. Did you create a access policy for you "hub entity"?
    This is the name space. For the code we need to use the Event hub under "entities". Click on "event hubs" under entities and check it that has an access policy. Be careful to don't confuse with the "namespace" access policy. both "hub namespace" and "hub entity" have access "policy". For this code you need the "hub entity" policy connection string. You know you've got the correct one when the connection string finishes with ";EntityPath=[hub name]"

    225953-image.png

    Did you set a access policy for you event hub entity?

    225870-image.png

    If I delete my access policy I get the exact same error as you

    225920-image.png

    check if you have the access policy set to manage. Ideally you should create 1 policy to send and another one to receive, but try a manage for now just to see it this is the issue.
    Also check if the hub network settings is not blocking your machine, You can temporarily select "All Networks" just to test :

    225923-image.png

    So, make sure you have a hub instance (not hub namespace) policy set to manage:
    225943-image.png

    if you have to create one, get the connection string from that and add to the code
    I also added code to force it to use websockets. try the above first. if it doesn't work, get a new version of my code

    225937-image.png