Get an Event Hubs connection string
To use Event Hubs, you need to create an Event Hubs namespace. A namespace is a scoping container for multiple event hubs or Kafka topics. This namespace gives you a unique FQDN. Once a namespace is created, you can obtain the connection string required to communicate with Event Hubs.
The connection string for Azure Event Hubs has the following components embedded within it,
- FQDN = the FQDN of the EventHubs namespace you created (it includes the EventHubs namespace name followed by servicebus.windows.net)
- SharedAccessKeyName = the name you chose for your application's SAS keys
- SharedAccessKey = the generated value of the key.
The connection string template looks like
An example connection string might look like
This article walks you through various ways of obtaining the connection string.
Get connection string from the portal
Sign in to Azure portal.
Select All services on the left navigational menu.
Select Event Hubs in the Analytics section.
In the list of event hubs, select your event hub.
On the Event Hubs Namespace page, select Shared Access Policies on the left menu.
Select a shared access policy in the list of policies. The default one is named: RootManageSharedAccessPolicy. You can add a policy with appropriate permissions (read, write), and use that policy.
Select the copy button next to the Connection string-primary key field.
Getting the connection string with Azure PowerShell
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
You can use the Get-AzEventHubKey to get the connection string for the specific policy/rule name as shown below:
Get-AzEventHubKey -ResourceGroupName MYRESOURCEGROUP -NamespaceName MYEHUBNAMESPACE -AuthorizationRuleName RootManageSharedAccessKey
Getting the connection string with Azure CLI
You can use the following to get the connection string for the namespace:
az eventhubs namespace authorization-rule keys list --resource-group MYRESOURCEGROUP --namespace-name MYEHUBNAMESPACE --name RootManageSharedAccessKey
Or you can use the following to get the connection string for an EventHub entity:
az eventhubs eventhub authorization-rule keys list --resource-group MYRESOURCEGROUP --namespace-name MYEHUBNAMESPACE --eventhub-name MYEHUB --name RootManageSharedAccessKey
For more information about Azure CLI commands for Event Hubs, see Azure CLI for Event Hubs.
You can learn more about Event Hubs by visiting the following links: