Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Create Event Hub resource

You will first need to create an Azure Event Hub namespace to send events to. Create an Event Hub namespace and assign to it a globally unique name. In the namespace you will then create an event hub named telemetry. You can use the following guidance to implement these changes:

In the next steps you will be connecting to the event hub through the workload identity you added in the spring-petclinic namespace. Make sure you assign this identity the Azure Event Hubs Data Owner permission on your event hub.

Step by step guidance

  1. On your lab computer, in the Git Bash window, from the Git Bash prompt, run the following command to create an Event Hub namespace. The name you use for your namespace should be globally unique, so adjust it accordingly in case the randomly generated name is already in use.

    EVENTHUBS_NAMESPACE=evhns-$APPNAME-$UNIQUEID
    
    az eventhubs namespace create \
      --resource-group $RESOURCE_GROUP \
      --name $EVENTHUBS_NAMESPACE \
      --location $LOCATION
    
  2. Next, create an event hub named telemetry in the newly created namespace.

    EVENTHUB_NAME=telemetry
    
    az eventhubs eventhub create \
      --name $EVENTHUB_NAME \
      --resource-group $RESOURCE_GROUP \
      --namespace-name $EVENTHUBS_NAMESPACE
    
  3. You will be connecting to the event hub with the workload identity you created earlier in the spring-petclinic namespace. You will need to provide this identity access to the event hub.

    az eventhubs namespace show --name $EVENTHUBS_NAMESPACE --resource-group $RESOURCE_GROUP --query id -o tsv
       
    EVENTHUB_ID=$(az eventhubs namespace show --name $EVENTHUBS_NAMESPACE --resource-group $RESOURCE_GROUP --query id -o tsv)
    echo $EVENTHUB_ID
       
    echo $USER_ASSIGNED_CLIENT_ID
    az role assignment create --assignee $USER_ASSIGNED_CLIENT_ID --role 'Azure Event Hubs Data Owner' --scope $EVENTHUB_ID