Search code examples
azure.net-coreazure-eventhub

Is it possible to create Azure event hub names if not found using .Net Core


I am looking for a solution to implement creating an Azure event hub name in .Net Core 3.1 If the event hub is not found when we add events assuming the event hub namespace has already been created.


Solution

  • Not possible in a direct manner using the packages, but can be achieve this , if you look at the backend code on Github,

    // Create namespace
    var namespaceName = "<populate some unique namespace>";
    Console.WriteLine($"Creating namespace... {namespaceName}");
    await ehClient.Namespaces.CreateOrUpdateAsync(resourceGroupName, namespaceName, namespaceParams);
        
    // Create eventhub.
    var ehParams = new Eventhub() { }; // Customize you eventhub here if you need.
    await ehClient.EventHubs.CreateOrUpdateAsync(resourceGroupName, namespaceName, ehName, ehParams);
    

    Here is a sample code available for reference