gpt4 book ai didi

azure - 将数据从 Azure 流分析存储到 Blob 存储时,是否可以在路径中添加 DeviceID

转载 作者:行者123 更新时间:2023-12-02 23:44:48 24 4
gpt4 key购买 nike

我将数据从不同的设备传入 IoT 中心,并使用流分析对其进行处理并将其存储在 Blob 存储中。我知道我们可以根据需要的格式在路径中添加我们添加的{date}{time},在该路径中我们也可以添加deviceId。

示例:2018/10/30/01(日期/月/日/小时)可以在存储到 blob 时在该路径中添加/deviceId enter image description here

最佳答案

以下是针对您的情况的解决方法示例。它基于使用 azure 函数 (HttpTrigger) 进行输出 ASA 作业,以推送方式将数据附加到特定的 Blob 存储。请注意,以下解决方法使用最大批处理计数将事件传递到 azure 函数值 1(一次一个遥测数据)。

ASA 职位查询:

SELECT
System.Timestamp as [time], *
INTO outAF
FROM
iot TIMESTAMP BY time

Azure 函数(HttpTrigger):

运行.csx

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public static async Task<IActionResult> Run(string body, CloudBlobContainer blobContainer, ILogger log)
{
log.LogInformation($"{body}");

var jtoken = JToken.Parse(body);
var jobject = jtoken is JArray ? jtoken.SingleOrDefault<JToken>() : jtoken;
if(jobject != null)
{
var jtext = jobject.ToString(Formatting.None);
var data = JsonConvert.DeserializeAnonymousType(jtext, new {IoTHub = new { ConnectionDeviceId = ""}});
var blobName = $"{DateTime.UtcNow.ToString("yyyy/MM/dd/hh")}/{data.IoTHub.ConnectionDeviceId}";
var blob = blobContainer.GetAppendBlobReference(blobName);
if(!await blob.ExistsAsync())
{
await blob.CreateOrReplaceAsync();
}
await blob.AppendTextAsync(jtext + "\r\n");
}
return new NoContentResult();

}

函数.json

    {
"bindings": [
{
"authLevel": "function",
"name": "body",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "blobContainer",
"type": "blob",
"path": "myContainer",
"connection": "mySTORAGE",
"direction": "out"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
]
}

关于azure - 将数据从 Azure 流分析存储到 Blob 存储时,是否可以在路径中添加 DeviceID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53069402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com