Walid
Walid

Reputation: 119

Microsoft Azure Iot hub

I have a device send frames of data to azure iot hub , What is the best practice to "translate these frames" and save it into SQL Db or Cosmos Db ?

Upvotes: 1

Views: 170

Answers (3)

iannovic
iannovic

Reputation: 44

Azure IOT Hub has a built in endpoint you can use by default called an Event Hub.You can create an Azure Function that consumes and processes all events tied to messages being routed to that event hub. By default, all your telemetry messages to IOT Hub will be routed to the build in EventHubs endpoint.

In your function, you could use a sql or cosmos client to write your data as needed. Here is a sample of what that may look like:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using Microsoft.Azure.EventHubs;
using System.Text;    

public static class EventHubFunctions
    {
        [FunctionName("ProcessEventHubQueue")]
        public static void Run(
    [EventHubTrigger("my-iot-eventhub", ConsumerGroup = "consumergroup1", Connection = "EventHubConnectionString")]
    EventData[] eventHubMessages,
    ILogger log)
        {
            foreach (EventData myEventHubMessage in eventHubMessages)
            {
               String messageBody = Encoding.UTF8.GetString(myEventHubMessage.Body);
               log.LogInformation($"EventData MessageBody: {messageBody}");

            }
        }

Upvotes: 0

TheTurkishDeveloper
TheTurkishDeveloper

Reputation: 187

You can use either Azure Stream Analytics or Azure Functions to process incoming telemetry data from Azure IoT Hub:

Stream Analytics

Azure Stream Analytics is a real-time analytics and complex event-processing engine that is designed to analyze and process high volumes of fast streaming data from multiple sources simultaneously. Patterns and relationships can be identified in information extracted from a number of input sources including devices, sensors, clickstreams, social media feeds, and applications. These patterns can be used to trigger actions and initiate workflows such creating alerts, feeding information to a reporting tool, or storing transformed data for later use. Also, Stream Analytics is available on Azure IoT Edge runtime, and supports the same exact language or syntax as cloud.

Azure Functions

In this quick sample you will learn how to capture data from your devices or sensors, perform aggregation, filtering or some other custom processing on this data, and store it on a database. All this will be done by setting up the integration between IoT Hub and Azure Functions, while learning a bit about triggers and bindings for Azure Functions, and drop your processed data on Cosmos DB.

Hope this helps!

Upvotes: 1

petermichael
petermichael

Reputation: 85

Try to read/browse the Azure IoT Reference Architecture: ref to architecture document

Cosmos DB would be my preferred starting point in most scenarios.

Remember to look into partitioning before you scale up the application. Also consider how you want to consume the data on the outbound side - because this will give valuable input to how you should organise and process the inbound data stream. Try to search for Lambda IoT architecture.

Upvotes: 0

Related Questions