Tutorial: Get Azure Event Hubs Connection String
Objective
This tutorial will guide you through the steps to retrieve the connection string for your Azure Event Hubs namespace. This connection string is essential for applications to connect to and interact with your Event Hubs.
Prerequisites
- An active Azure subscription.
- An Azure Event Hubs namespace created within your subscription.
- The Event Hubs namespace must have at least one Event Hub created within it.
Steps to Get the Connection String
1.
Navigate to the Azure Portal: Open your web browser and go to
https://portal.azure.com/. Log in with your Azure account credentials.
2.
Find Your Event Hubs Namespace:
- In the Azure portal search bar at the top, type "Event Hubs namespaces" and select it from the results.
- On the "Event Hubs namespaces" page, locate and click on the name of the specific namespace you want to get the connection string for.
3.
Access Shared Access Policies:
- Once you are on the overview page of your Event Hubs namespace, look for the "Settings" section in the left-hand navigation menu.
- Click on "Shared access policies".
4.
Select or Create a Policy:
- You will see a list of shared access policies. The default policy is usually named
RootManageSharedAccessKey, which grants full access.
- For production scenarios, it's recommended to create a more granular policy with specific permissions (e.g., only send or only listen). You can click "+ Add" to create a new policy.
- For this tutorial, you can use the
RootManageSharedAccessKey or any other policy that has the required permissions. Click on the name of the policy you want to use.
5.
Copy the Connection String:
- On the "Shared access policy" page, you will find two connection strings: "Primary connection string" and "Secondary connection string".
- Click the copy icon next to the "Primary connection string".
Security Note: Treat your connection strings like passwords. Do not share them publicly or embed them directly in client-side code. Use secure methods like environment variables or Azure Key Vault for managing secrets.
Using the Connection String
You can now use this connection string in your applications (e.g., .NET, Python, Java, Node.js) to connect to your Azure Event Hubs. Here's a simplified example of how it might look:
Endpoint=sb://your-event-hubs-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOUR_PRIMARY_KEY
Replace your-event-hubs-namespace.servicebus.windows.net/ with your actual namespace and YOUR_PRIMARY_KEY with the copied primary key.
Next Steps
Now that you have your connection string, you can proceed to: