Getting Started with Azure Event Hubs
Welcome to the Getting Started guide for Azure Event Hubs! This section will walk you through the essential steps to set up and begin using Event Hubs for your event streaming needs.
1. Prerequisites
- An Azure Subscription. If you don't have one, sign up for a free account.
- The Azure CLI installed or access to the Azure portal.
2. Create an Event Hubs Namespace
An Event Hubs namespace is a logical container for Event Hubs. All Event Hubs and consumer groups reside within a namespace.
Using Azure Portal:
- Navigate to the Azure portal.
- Click on "Create a resource".
- Search for "Event Hubs" and select it.
- Click "Create".
- Select your subscription and resource group.
- Enter a unique namespace name.
- Choose a location.
- Select a pricing tier (e.g., Basic or Standard).
- Click "Review + create", then "Create".
Using Azure CLI:
az group create --name MyEventHubsResourceGroup --location eastus
az eventhubs namespace create --name MyEventHubsNamespace --resource-group MyEventHubsResourceGroup --location eastus
3. Create an Event Hub
An Event Hub is the actual streaming entity where events are sent and read from.
Using Azure Portal:
- Once your Event Hubs namespace is created, navigate to it in the Azure portal.
- Click on "+ Event Hub".
- Enter a name for your Event Hub (e.g.,
myeventhub). - Configure settings like message retention and partitioning if needed.
- Click "Create".
Using Azure CLI:
az eventhubs eventhub create --name myeventhub --namespace-name MyEventHubsNamespace --resource-group MyEventHubsResourceGroup
4. Get Connection Strings
To send or receive events, you'll need connection strings. These contain authentication and endpoint information.
Using Azure Portal:
- Navigate to your Event Hubs namespace.
- Under "Settings", click "Shared access policies".
- You can use the "RootManageSharedAccessKey" for convenience, or create a custom policy with specific permissions.
- Click on a policy name to view its keys and connection strings. Copy the "Primary Connection String".
Using Azure CLI:
az eventhubs authorization-rule list --namespace-name MyEventHubsNamespace --resource-group MyEventHubsResourceGroup --output table
# From the output, find the connection string for your chosen policy (e.g., RootManageSharedAccessKey)
It's recommended to create specific policies for sending and receiving operations rather than using the root key in production environments.
5. Install an SDK
Azure Event Hubs offers SDKs for various programming languages. Choose the one that best suits your application.
For example, to install the Python SDK:
pip install azure-eventhub
Next Steps
Now that you have Event Hubs set up and an SDK installed, you're ready to start sending and receiving events. Proceed to the Sending Events guide.
Send Your First Event