Message routing enables the sending of telemetry data from an IoT Hub to custom endpoints or Event-Hub endpoints. Once the setup is done, telemetry will automatically route to the endpoints from IoT device to the IoT Hub. Please read the previous parts of the article before continuing with this one.
- How To Create Azure IoT Hub Using PowerShell
- How to Register IoT Device in Azure IoT Hub Using PowerShell
- How To Send Telemetry From An IoT Device To The Azure IoT Hub Using C#
Routing message to a storage account
- Open your Azure portal and log in to your Azure account and choose your IoT Hub.
- Click Message Routing in the "Message Routing" pane. You can see the list of routes and custom endpoints.
- Click the +Add button on the Routes pane. Click the +Add button next to Endpoint field, like in the below picture.
- Choose Blob storage from the options, and a storage endpoint will be displayed.
- Enter the name for your endpoint. Here, we use IoTStorageEndpoint.
Click "Pick a container". It will take you to the list of storage containers that we have created in the Azure portal.
- Choose any one of the storage accounts. Here, I chose hfazureiotjstextx. Then, it will display the containers like below.
- Click the "+Containers" button and enter the new name and access level for the container.
- Then, click OK.
- Select the newly created container. It will return to the "Add a storage endpoint" pane.
- Use default for the rest of the fields. You can create the blob name using Blob file name format.
- The default is {iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}. The blob name will look like this HubflyIoTHubConnect/0/2019/02/12/18/05. The blobs are written in Avro format
- Click "Create" to create the storage endpoint. It will return to the "Add a route" pane.
- Now, enter the route name. Here, we used IoTRoute.
- Choose the data source as Device Telemetry Messages from the drop-down list.
- Enable Route: Be sure this is enabled.
- Route Query: Enter the route query string as “level=”storage”.
- Click "Save". It will return to the Message routing pane like in the below image.
That's It. You have learned how to configure message routing to a storage account with IoT Hub. Feel free to fill up the comment box below if you need any further assistance.