简体   繁体   English

Microsoft Azure 物联网中心

[英]Microsoft Azure Iot hub

我有一个设备向 azure iot hub 发送数据帧,“翻译这些帧”并将其保存到 SQL Db 或 Cosmos Db 的最佳实践是什么?

You can use either Azure Stream Analytics or Azure Functions to process incoming telemetry data from Azure IoT Hub:可以使用 Azure 流分析或 Azure Functions 来处理来自 Azure IoT 中心的传入遥测数据:

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. Azure Stream Analytics 是一种实时分析和复杂的事件处理引擎,旨在同时分析和处理来自多个源的大量快速流数据。 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 IoT Edge 运行时,并支持与云完全相同的语言或语法。

Azure Functions Azure 函数

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.所有这一切都将通过设置 IoT 中心和 Azure Functions 之间的集成来完成,同时了解一些有关 Azure Functions 的触发器和绑定的知识,并将处理后的数据放到 Cosmos DB 上。

Hope this helps!希望这可以帮助!

Try to read/browse the Azure IoT Reference Architecture: ref to architecture document尝试阅读/浏览 Azure IoT 参考架构:参考架构文档

Cosmos DB would be my preferred starting point in most scenarios.在大多数情况下,Cosmos DB 将是我首选的起点。

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.尝试搜索 Lambda IoT 架构。

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. Azure IOT 中心有一个内置端点,您可以默认使用它,称为事件中心。您可以创建一个 Azure 函数来使用和处理与路由到该事件中心的消息相关的所有事件。 By default, all your telemetry messages to IOT Hub will be routed to the build in EventHubs endpoint.默认情况下,您发送到 IOT Hub 的所有遥测消息都将路由到 EventHubs 端点中的构建。

In your function, you could use a sql or cosmos client to write your data as needed.在您的函数中,您可以根据需要使用 sql 或 cosmos 客户端写入数据。 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}");

            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM