How To Configure Message Routing With IoT Hub - Part One

Introduction

 
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.
  1. How To Create Azure IoT Hub Using PowerShell
  2. How to Register IoT Device in Azure IoT Hub Using PowerShell
  3. 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.
How To Configure Message Routing With IoT Hub
  • Click the +Add button on the Routes pane. Click the +Add button next to Endpoint field, like in the below picture.
How To Configure Message Routing With IoT Hub
  • 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.
 
How To Configure Message Routing With IoT Hub
  • Choose any one of the storage accounts. Here, I chose hfazureiotjstextx. Then, it will display the containers like below.
How To Configure Message Routing With IoT Hub
  • Click the "+Containers" button and enter the new name and access level for the container.
  • Then, click OK.
How To Configure Message Routing With IoT Hub
  • Select the newly created container. It will return to the "Add a storage endpoint" pane.
How To Configure Message Routing With IoT Hub
  • 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”.
How To Configure Message Routing With IoT Hub
  • Click "Save". It will return to the Message routing pane like in the below image.
How To Configure Message Routing With IoT Hub 
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.