| title | Export data to Event Hubs | ||
|---|---|---|---|
| description | Learn how to use the IoT Central data export capability to continuously export your IoT data to Event Hubs | ||
| services | iot-central | ||
| author | dominicbetts | ||
| ms.author | dobett | ||
| ms.date | 08/06/2025 | ||
| ms.topic | how-to | ||
| ms.service | azure-iot-central | ||
| ms.custom |
|
This article describes how to configure data export to send data to the Event Hubs.
[!INCLUDE iot-central-data-export]
IoT Central exports data in near real time. The data is in the message body and is in JSON format encoded as UTF-8.
The annotations or system properties bag of the message contains the iotcentral-device-id, iotcentral-application-id, iotcentral-message-source, and iotcentral-message-type fields that have the same values as the corresponding fields in the message body.
Event Hubs destinations let you configure the connection with a connection string or a managed identity.
[!INCLUDE iot-central-managed-identities]
This article shows how to create a managed identity using the Azure CLI. You can also use the Azure portal to create a managed identity.
If you don't have an existing Event Hubs namespace to export to, run the following script in the Azure Cloud Shell bash environment. The script creates a resource group, Event Hubs namespace, and event hub. The script then enables the managed identity for your IoT Central application and assigns the role it needs to access your event hub:
# Replace the Event Hubs namespace name with your own unique value
EHNS=your-event-hubs-namespace-$RANDOM
# Replace the IoT Central app name with the name of your
# IoT Central application.
CA=your-iot-central-app
EH=exportdata
RG=centralexportresources
LOCATION=eastus
RGID=$(az group create -n $RG --location $LOCATION --query "id" --output tsv)
az eventhubs namespace create --name $EHNS --resource-group $RG -l $LOCATION
az eventhubs eventhub create --name $EH --resource-group $RG --namespace-name $EHNS
# This assumes your IoT Central application is in the
# default `IOTC` resource group.
az iot central app identity assign --name $CA --resource-group IOTC --system-assigned
PI=$(az iot central app identity show --name $CA --resource-group IOTC --query "principalId" --output tsv)
az role assignment create --assignee $PI --role "Azure Event Hubs Data Sender" --scope $RGID
az role assignment list --assignee $PI --all -o table
echo "Host name: $EHNS.servicebus.windows.net"
echo "Event Hub: $EH"
To further secure your event hub and only allow access from trusted services with managed identities, see Export data to a secure destination on an Azure Virtual Network.
To create the Event Hubs destination in IoT Central on the Data export page:
-
Select + New destination.
-
Select Azure Event Hubs as the destination type.
-
Select System-assigned managed identity as the authorization type.
-
Enter the host name of your Event Hubs resource. Then enter the case-sensitive event hub name. A host name looks like:
contoso-waste.servicebus.windows.net. -
Select Save.
If you don't see data arriving in your destination service, see Troubleshoot issues with data exports from your Azure IoT Central application.
If you don't have an existing Event Hubs namespace to export to, run the following script in the Azure Cloud Shell bash environment. The script creates a resource group, Event Hubs namespace, and event hub. It then prints the connection string to use when you configure the data export in IoT Central:
# Replace the Event Hubs namespace name with your own unique value
EHNS=your-event-hubs-namespace-$RANDOM
EH=exportdata
RG=centralexportresources
LOCATION=eastus
az group create -n $RG --location $LOCATION
az eventhubs namespace create --name $EHNS --resource-group $RG -l $LOCATION
az eventhubs eventhub create --name $EH --resource-group $RG --namespace-name $EHNS
az eventhubs eventhub authorization-rule create --eventhub-name $EH --resource-group $RG --namespace-name $EHNS --name SendRule --rights Send
CS=$(az eventhubs eventhub authorization-rule keys list --eventhub-name $EH --resource-group $RG --namespace-name $EHNS --name SendRule --query "primaryConnectionString" -o tsv)
echo "Event hub connection string: $CS"
To create the Event Hubs destination in IoT Central on the Data export page:
-
Select + New destination.
-
Select Azure Event Hubs as the destination type.
-
Select Connection string as the authorization type.
-
Paste in the connection string for your Event Hubs resource, and enter the case-sensitive event hub name if necessary.
-
Select Save.
[!INCLUDE iot-central-data-export-setup]
[!INCLUDE iot-central-data-export-message-properties]
[!INCLUDE iot-central-data-export-device-connectivity]
[!INCLUDE iot-central-data-export-device-lifecycle]
[!INCLUDE iot-central-data-export-device-template]
[!INCLUDE iot-central-data-export-audit-logs]
For Event Hubs, IoT Central exports new messages data to your event hub in near real time. In the user properties (also referred to as application properties) of each message, the iotcentral-device-id, iotcentral-application-id, iotcentral-message-source, and iotcentral-message-type are included automatically.
Now that you know how to export to Event Hubs, a suggested next step is to learn how to export IoT data to Azure Data Explorer.