How To Configure Message Routing With IoT Hub - Part Two

Message routing enables sending telemetry data from IoT Hub to custom endpoints or Event-Hub endpoints. Once the set up is done, telemetry from IoT device to IoT Hub will automatically be routed to the endpoints. Here, we will route a message to Azure Tables.

What is Azure Stream Analytics?

Azure Stream Analytics is an event process which allows you to examine the high-level data that streams from IoT devices. Incoming data can be from IoT devices, social media feeds, applications, and more.

Please read the previous parts of the article before continuing with this one.

Set up Azure Stream Analytics

Create Stream Analytics job

  • Open your Azure portal and log in to your Azure account.
  • Click Create a resource -> Internet Of Things -> Stream Analytics job
How To Configure Message Routing With IoT Hub
  • Enter the following pieces of information

    • Job name: Name of the job. Should be globally unique.

    • Resource group: Use the same resource group in which IoT Hub is created

    • Location: Use the location where the IoT Hub is created

How To Configure Message Routing With IoT Hub
  • Click Create to create the job.

How To Configure Message Routing With IoT Hub

The HubflyIoTJob named Stream Analytics Job is going to transfer the messages from the IoT Hub to an Azure Storage Table. Follow the below steps to configure,

  • Under Job Topology, select Inputs.
  • Click +Add stream input and choose IoT Hub.
  • Enter the Input alias name. Here, I named it as HubInput.
  • Choose Event Serialization format as JSON.
 How To Configure Message Routing With IoT Hub
  • Under Job topology, click Outputs.
  • Click +Add and choose Table Storage.
How To Configure Message Routing With IoT Hub
 
  • Enter the output alias name. Here, I name it as TableOutput.
  • Choose Storage account where the message to be saved.
  • Enter the table name. Here, I named it as HubflyIoTHubConnect.
  • Enter the Partition Key and RowKey. I choose Partition key as DeviceId and Row Key as MessageId.
How To Configure Message Routing With IoT Hub
  • Click "Save" to add Table storage as output.

How To Configure Message Routing With IoT Hub
  • The last step is to create a query. We are using a basic query, that is, “SELECT * INTO TableOutput FROM HubInput”.
  • Click "Save".
How To Configure Message Routing With IoT Hub
  • Now, go to Overview, click Start.
How To Configure Message Routing With IoT Hub
  • When this is done, just hit "Start" and connect to your Azure Tables using the Storage Explorer.

How To Configure Message Routing With IoT Hub
  • Now, send the telemetry to IoT Hub. It will route a message to Azure Tables using Stream Analytics job.

Output
 
How To Configure Message Routing With IoT Hub

That’s it. I hope you have learned how to configure message routing with Azure IoT Hub using Azure Stream Analytics. Feel free to fill up the comment box below if you need any further assistance from us.