Get an Event Hubs connection string
To use Event Hubs, you need to create an Event Hubs namespace. A namespace is a scoping container that can house multiple Event Hubs / 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 (this will include 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
Once you have the Event Hubs namespace, the overview section of the portal can give you the connection string as shown below:
When you click on the connection string link in the overview section, it opens the SAS policies tab as shown in the figure below:
You can either add a new SAS policy and get the connection string or use the default policy that is already created for you. When the policy is opened, the connection string is obtained as shown in the below figure:
Getting the connection string with Azure PowerShell
This article has been updated to use the new Azure PowerShell Az module. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For 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
Refer to Azure Event Hubs PowerShell module for more details.
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
Refer to Azure CLI for Event Hubs to learn more.
You can learn more about Event Hubs by visiting the following links:
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.