将分析出口流式传输到 Azure Functions
Stream Analytics Egress to Azure Functions
Microsoft 几天前宣布支持将数据从 Azure Stream Analytics 发送到 Azure Functions:
我试过了,但无法将数据发送到 Azure Functions。有没有关于如何从 IoT-hub -> Azure Stream Analytics -> Azure Functions 发送数据包的指南?
其他来源的输出没问题。这是我的查询:
WITH rpidata AS
(
SELECT
*,
DATEADD(Hour, 3, timecreated) AS FITimezone
FROM [rpi]
)
SELECT *
INTO [PowerBI]
FROM rpidata
SELECT *
INTO [storageout]
FROM rpidata
SELECT *
INTO [fnout]
FROM rpidata
我收到的错误信息是:
Could not successfully send an empty batch to the Azure Function. Please make sure your function app name, function name, and API key are correct and that your Azure Function compiles. If all of those parameters are correct, Azure Function may be temporarily available at this time. Please try again later. Azure function returned with response code of 500: InternalServerError. It should respond with a 200, 202, or 204.
然而,该功能存在,是 运行 并且在我尝试创建连接时自动找到。
我应该使用什么样的函数输入来接收数据?在示例中,我链接的函数名称是 httptriggercsharp ... streamjob 是否将数据发送为 json?
根据你的描述和报错信息,我猜你的 azure 函数代码有问题(returns 500 错误)。
我建议您可以先查看 azure 函数日志,找到详细的错误消息并更改您的代码。
详情可参考下图:
打开 azure function app 找到 monitor
我还为 azure 函数创建了一个测试流分析。我发现流分析会将 json 发送到 azure 函数。
我建议你也可以使用这个代码(Http trigger)来测试你能得到结果:
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var content = req.Content;
string jsonContent = await content.ReadAsStringAsync();
log.Info(jsonContent);
return req.CreateResponse(HttpStatusCode.OK, jsonContent);
}
结果:
不确定您是否仍然需要它,但供将来参考:ASA 作业会将 JSON 数组中的数据输出到您的 Azure 函数。
像这样的示例 ASA 查询
SELECT
w.col1 as key1,
w.col2 as key2,
System.Timestamp as time
INTO
azfunction
FROM
[input] w;
将像这样到达您的函数
[
{
"key1":"value1",
"key2":"value2",
"time":"2017-09-04T17:51:02.7986986Z"
},
{
"key1":"value3",
"key2":"value4",
"time":"2017-09-04T17:51:02.7986986Z"
}
]
JSON 数组将包含多少元素取决于您在 ASA 中设置 Az 函数输出的方式以及事件到达 ASA 的速度。根据您的情况,该数组可能只有一个元素或 100 个元素。
为了补充这个答案,您可以使用 mockaroo 的模拟数据。
测试上述代码:
{
"DeviceID": 8,
"Temperature": 28,
"Unit": 40,
"TimeStamp": "2018-03-23T17:43:18.0000000Z",
"EventProcessedUtcTime": "2018-03-23T17:44:36.5010819Z",
"PartitionId": 0,
"EventEnqueuedUtcTime": "2018-03-23T17:43:18.5700000Z"
},
{
"DeviceID": 8,
"Temperature": 66,
"Unit": 27,
"TimeStamp": "2018-03-23T17:43:20.0000000Z",
"EventProcessedUtcTime": "2018-03-23T17:44:36.8143642Z",
"PartitionId": 1,
"EventEnqueuedUtcTime": "2018-03-23T17:43:21.0090000Z"
}
Microsoft 几天前宣布支持将数据从 Azure Stream Analytics 发送到 Azure Functions:
我试过了,但无法将数据发送到 Azure Functions。有没有关于如何从 IoT-hub -> Azure Stream Analytics -> Azure Functions 发送数据包的指南?
其他来源的输出没问题。这是我的查询:
WITH rpidata AS
(
SELECT
*,
DATEADD(Hour, 3, timecreated) AS FITimezone
FROM [rpi]
)
SELECT *
INTO [PowerBI]
FROM rpidata
SELECT *
INTO [storageout]
FROM rpidata
SELECT *
INTO [fnout]
FROM rpidata
我收到的错误信息是:
Could not successfully send an empty batch to the Azure Function. Please make sure your function app name, function name, and API key are correct and that your Azure Function compiles. If all of those parameters are correct, Azure Function may be temporarily available at this time. Please try again later. Azure function returned with response code of 500: InternalServerError. It should respond with a 200, 202, or 204.
然而,该功能存在,是 运行 并且在我尝试创建连接时自动找到。
我应该使用什么样的函数输入来接收数据?在示例中,我链接的函数名称是 httptriggercsharp ... streamjob 是否将数据发送为 json?
根据你的描述和报错信息,我猜你的 azure 函数代码有问题(returns 500 错误)。
我建议您可以先查看 azure 函数日志,找到详细的错误消息并更改您的代码。
详情可参考下图:
打开 azure function app 找到 monitor
我还为 azure 函数创建了一个测试流分析。我发现流分析会将 json 发送到 azure 函数。
我建议你也可以使用这个代码(Http trigger)来测试你能得到结果:
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var content = req.Content;
string jsonContent = await content.ReadAsStringAsync();
log.Info(jsonContent);
return req.CreateResponse(HttpStatusCode.OK, jsonContent);
}
结果:
不确定您是否仍然需要它,但供将来参考:ASA 作业会将 JSON 数组中的数据输出到您的 Azure 函数。 像这样的示例 ASA 查询
SELECT
w.col1 as key1,
w.col2 as key2,
System.Timestamp as time
INTO
azfunction
FROM
[input] w;
将像这样到达您的函数
[
{
"key1":"value1",
"key2":"value2",
"time":"2017-09-04T17:51:02.7986986Z"
},
{
"key1":"value3",
"key2":"value4",
"time":"2017-09-04T17:51:02.7986986Z"
}
]
JSON 数组将包含多少元素取决于您在 ASA 中设置 Az 函数输出的方式以及事件到达 ASA 的速度。根据您的情况,该数组可能只有一个元素或 100 个元素。
为了补充这个答案,您可以使用 mockaroo 的模拟数据。
测试上述代码:
{
"DeviceID": 8,
"Temperature": 28,
"Unit": 40,
"TimeStamp": "2018-03-23T17:43:18.0000000Z",
"EventProcessedUtcTime": "2018-03-23T17:44:36.5010819Z",
"PartitionId": 0,
"EventEnqueuedUtcTime": "2018-03-23T17:43:18.5700000Z"
},
{
"DeviceID": 8,
"Temperature": 66,
"Unit": 27,
"TimeStamp": "2018-03-23T17:43:20.0000000Z",
"EventProcessedUtcTime": "2018-03-23T17:44:36.8143642Z",
"PartitionId": 1,
"EventEnqueuedUtcTime": "2018-03-23T17:43:21.0090000Z"
}