Monday 31 October 2016

EventHub - No connection could be made because the target machine actively refused it 127.0.0.1:10000

I recently trying out a simple POC that listens to messages from Azure EventHub. I referred to the online documentation and everything was very simple to set up.

I set up separate policies for Listen and Send and used those to set up simple code that sends and listens to a message. The code was fairly simple but it failed :)

        static string eventHubName = "eventhub1";
        static string listeneventHubConnectionString = "";
        static string sendeventHubConnectionString = "";
        static string storageConnectionString = "UseDevelopmentStorage=true";

        static void Main(string[] args)
        {

            Console.WriteLine("Press Ctrl-C to stop the sender process");
            Console.WriteLine("Press Enter to start now");
            Console.ReadLine();
            SendingRandomMessages();

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, listeneventHubConnectionString, storageConnectionString);
            Console.WriteLine("Registering EventProcessor...");
            var options = new EventProcessorOptions();
            options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
            eventProcessorHost.RegisterEventProcessorAsync(options).Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();

       }

Here is the exception:

{"Unable to connect to the remote server"}



At first the exception seemed a little misguiding - you get an impression that eventhub is not reachable or you have typed the connectionstring incorrectly. However, if you look at the error stack details, it turns out that Azure Storage Emulator is not started on the machine :). You get more hints when you start digging into the exception details.


{"No connection could be made because the target machine actively refused it 127.0.0.1:10000"}  
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)


No comments:

Post a Comment