Event Hubs management libraries

You can use the Azure Event Hubs management libraries to dynamically provision Event Hubs namespaces and entities. This dynamic nature enables complex deployments and messaging scenarios, so that you can programmatically determine what entities to provision. These libraries are currently available for .NET.

Supported functionality

  • Namespace creation, update, deletion
  • Event Hubs creation, update, deletion
  • Consumer Group creation, update, deletion

Prerequisites

To get started using the Event Hubs management libraries, you must authenticate with Azure Active Directory (AAD). AAD requires that you authenticate as a service principal, which provides access to your Azure resources. For information about creating a service principal, see one of these articles:

These tutorials provide you with an AppId (Client ID), TenantId, and ClientSecret (authentication key), all of which are used for authentication by the management libraries. You must have Owner permissions for the resource group on which you want to run.

Programming pattern

The pattern to manipulate any Event Hubs resource follows a common protocol:

  1. Obtain a token from AAD using the Microsoft.IdentityModel.Clients.ActiveDirectory library.

    var context = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}");
    
    var result = await context.AcquireTokenAsync(
        "https://management.core.windows.net/",
        new ClientCredential(clientId, clientSecret)
    );
    
  2. Create the EventHubManagementClient object.

    var creds = new TokenCredentials(token);
    var ehClient = new EventHubManagementClient(creds)
    {
        SubscriptionId = SettingsCache["SubscriptionId"]
    };
    
  3. Set the CreateOrUpdate parameters to your specified values.

    var ehParams = new EventHubCreateOrUpdateParameters()
    {
        Location = SettingsCache["DataCenterLocation"]
    };
    
  4. Execute the call.

    await ehClient.EventHubs.CreateOrUpdateAsync(resourceGroupName, namespaceName, EventHubName, ehParams);
    

Next steps