0
votes

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send

I am following that tutorial about event hub and I am having issues to connect to the event grid with the exact same code. Have anyone faced a similar issue before?

namespace EventHub
{
    class Program
    {
        private const string connectionString = "Endpoint=sb://emailsevents.servicebus.windows.net/;SharedAccessKeyName=randomaccess;SharedAccessKey=<my_key>";
        private const string eventHubName = "emailsevents.servicebus.windows.net";
        private static async Task Main()
        {
            // Create a producer client that you can use to send events to an event hub
            await using (var producerClient = new EventHubProducerClient(connectionString, eventHubName))
            {
                // Create a batch of events 
                using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
                // Add events to the batch. An event is a represented by a collection of bytes and metadata. 
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("First event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Second event")));
                eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Third event")));
                // Use the producer client to send the batch of events to the event hub
                await producerClient.SendAsync(eventBatch);
                Console.WriteLine("A batch of 3 events has been published.");
            }
        }
    }
}

I am getting a Unhandled exception. EventHubsException(ResourceNotFound) When I hit the line

        using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
1

1 Answers

2
votes

You're providing your Event Hubs namespace rather than the name of the Event Hub instance under that namespace that you'd like to publish to.

Depending on how you created your namespace, you may or may not have an Event Hub available to use. The names of the Event Hubs for a namespace are listed in a grid at the bottom of the screen in the Azure portal when looking at an Event Hubs resource. (in the example, mine is called "dummy"). If you're not seeing any items in that grid, you can create one using the + Event Hub button in the top menu bar.

Once you know the name of the Event Hub that you'd like to publish to, you'll set that in this line of your code:

private const string eventHubName = "emailsevents.servicebus.windows.net";

enter image description here