Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in
This guide shows you how to provision an Event Hubs Namespace and an event hub against Locally. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.
az) installed.Firstly, we need to launch Locally which we can do from a terminal by running:
$
locally build
Once Locally has started, the Locally Dashboard will open automatically:
Next we can create the Resource Group to hold the namespace:
$
locally run az group create -n sample-resources -l berlin
There's two things to note here:
locally run.locally run when you do.With the Resource Group in place, we can create the Event Hubs Namespace:
$
locally run az eventhubs namespace create --name samplehubs1 --resource-group sample-resources --location berlin
Note
{
"note": "some fields skipped for brevity",
"location": "berlin",
"name": "samplehubs1",
"provisioningState": "Succeeded",
"resourceGroup": "sample-resources",
"status": "Active",
"type": "Microsoft.EventHub/Namespaces"
}
A namespace is just a container, so next we'll create an event hub inside it. Event Hubs partitions its stream, and the partition count is fixed at creation, so it's the one setting worth thinking about up front:
$
locally run az eventhubs eventhub create --name telemetry --namespace-name samplehubs1 --resource-group sample-resources --partition-count 4
Which gives us the hub along with the IDs of its partitions:
{
"note": "some fields skipped for brevity",
"name": "telemetry",
"partitionCount": 4,
"partitionIds": [
"0",
"1",
"2",
"3"
],
"status": "Active",
"type": "Microsoft.EventHub/Namespaces/EventHubs"
}
We can list the hubs in the namespace at any point:
$
locally run az eventhubs eventhub list --namespace-name samplehubs1 --resource-group sample-resources --query "[].{Name:name, Partitions:partitionCount, Status:status}" -o table
Name Partitions Status
--------- ------------ --------
telemetry 4 Active
Consumers read from an event hub through a consumer group, which is how two independent readers can each track their own position in the stream. Every hub starts with one called $Default, and we can add our own:
$
locally run az eventhubs eventhub consumer-group create --name processor --eventhub-name telemetry --namespace-name samplehubs1 --resource-group sample-resources
{
"name": "processor",
"type": "Microsoft.EventHub/namespaces/eventhubs/consumerGroups"
}
Locally has a built-in helper for listing them, which shows the default alongside ours:
$
locally eventhub consumer-group list --namespace samplehubs1 --hub telemetry
NAME
$Default
processor
To have an application publish and consume events, we need the namespace's connection string. Locally has a helper for this too:
$
locally eventhub connection-string --namespace samplehubs1
Endpoint=sb://samplehubs1.eventhub.locally;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=...
Note
locally eventhub is part of Locally itself rather than a tool being configured, so it doesn't take the locally run prefix. Every az command does.That eventhub.locally hostname is served by Locally's own DNS server and points at the Event Hubs Emulator running on your machine.
Locally also lets you look at what's landed in a partition without consuming it, which is handy while you're debugging a producer. Since Event Hubs is partitioned, you peek one partition at a time:
$
locally eventhub hub peek --namespace samplehubs1 --name telemetry --partition 0
As we haven't published anything yet:
No events in event hub "telemetry" partition 0.
We can see the Event Hubs Namespace in the Locally Dashboard too:
Finally, we can tidy up. To remove the Resource Group and everything within it:
$
locally run az group delete -n sample-resources --yes
There's nothing billable to clean up, since everything ran on your machine, but it's still worth checking your teardown scripts work here before you run them against Azure.
Whilst this guide used the Azure CLI, Event Hubs works the same way through any of the tooling that Locally supports - Microsoft.EventHub/namespaces and Microsoft.EventHub/namespaces/eventhubs resources in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.
The Event Hubs Emulator lets you send events from the browser and pause a hub. To consume events in code, a Function App can use an Event Hubs trigger, and IoT Hub telemetry arrives through Event Hubs too.
Should you encounter any issues, please take a look at the troubleshooting section.
Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in
Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.