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 new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.
You can use the Get-AzEventHubNamespaceKey to get the connection string for the specific policy/rule name as shown below:
Get-AzEventHubKey -ResourceGroupName dummyresourcegroup -NamespaceName dummynamespace -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 dummyresourcegroup --namespace-name dummynamespace --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: