将数据从函数提取到事件中心,再到 Azure 数据资源管理器?
Ingesting data from a function, to an event hub, to Azure Data Explorer?
我有一些 JSON 数据进入物联网中心,然后触发一个函数来取消嵌套数据。
该函数将此数据发送到事件中心,然后该数据应该根据我设置的映射由 Azure 数据资源管理器摄取。
问题是没有数据进入数据浏览器;它将通过映射接收数据的唯一方法是将源设置为通过自定义路由接收信息的事件中心。
是否可以通过物联网中心 -> 功能 -> 事件中心在数据资源管理器中提取数据?
编辑:
用于取消嵌套数据并将其转发到另一个事件中心的函数:
module.exports = async function (context, eventHubMessages) {
// receive message from IOT hub
eventHubMessages.forEach((message, index) => {
var devicename = message.deviceName;
// timestamp comes in two different texts, find and store correct one
var timestamp = (message.timestamp == null) ? message.timeStamp : message.timestamp;
//context.log("Message: " + JSON.stringify(message));
if (message.tags != null) {
message.tags.forEach((tag, index) => {
// for each tag, create new object
var name = tag.Name;
var value = tag.Value;
var newObject = {
"name":name,
"value": value,
"eventenqueuedutctime": timestamp,
"devicename": devicename
}
// output message object to 'splitmessage-dev' event hub
context.bindings.outputEventHubMessage = newObject
context.log("Sent object: " + JSON.stringify(newObject));
})
}
});
};
我可以确认其他事件中心正在接收此数据(使用另一个打印传入消息的函数进行检查)。
映射如下所示:
'testTableMap' '[{"column":"name", "path":"$.name"},
{"column":"value", "path":"$.value"},
{"column":"eventenqueuedutctime", "path":"$.eventenqueuedutctime"},
{"column":"devicename", "path":"$.devicename"}]'
应该可以使用您提供的设置摄取数据。
由于数据未被摄取,您可能应该尝试诊断卡在何处。
我将提供一些有助于调试的一般准则。
数据未到达配置为 ADX 数据源的 EventHub
您可以检查 EventHub 监控并验证事件是否在流动。
此外,我建议从 EventHub 读取数据,以确保它看起来像您期望的那样。 (好像你已经这样做了)
这里的情况似乎并非如此,因为您已经阐明您确实看到了流入 EventHub 的事件,并且您可以通过另一个函数成功读取它们。
Table / 映射配置不正确
尝试从配置的 EventHub 获取数据 manually
// create table
// I am assuming strings because other types can cause format errors,
// so I would try strings before other specific types (dynamic, datetime)
.create table IngestionTest (name: string, value:string, eventenqueuedutctime:string, devicename:string)
// add mapping
.create table IngestionTest ingestion json mapping 'testTableMap' '[{"column":"name", "path":"$.name"}, {"column":"value", "path":"$.value"}, {"column":"eventenqueuedutctime", "path":"$.eventenqueuedutctime"},{"column":"devicename", "path":"$.devicename"}]'
// ingest data manually - replace with you actual data
.ingest inline into table IngestionTest with (jsonMappingReference='testTableMap') <| '{ "name" : "test", "value": { "some":"nested", "value": true}, "eventenqueuedutctime" : "2016-01-14", "devicename": "surface" }'
如果上述方法不起作用,您可以通过 listing ingestion errors
尝试了解原因
.show ingestion failures
如果以上方法有效,您可以尝试使用其他数据类型。
数据源监控
您可以通过 Azure 门户检查的另一件事是 ADX 集群的指标。
尝试在 Azure 门户中转到您的集群,在 Metrics
选项卡中,您可以选择两个可帮助您进行故障排除的指标:
Events Processed
- 让您了解 ADX 设法从 EventHub 读取了多少事件。这基本上让您知道数据源配置正确。如果您看不到事件,我建议您设置一个新的来源。
Ingestion Result
- 为您提供摄取状态(成功/失败)的计数,这也有助于诊断失败。
我有一些 JSON 数据进入物联网中心,然后触发一个函数来取消嵌套数据。
该函数将此数据发送到事件中心,然后该数据应该根据我设置的映射由 Azure 数据资源管理器摄取。
问题是没有数据进入数据浏览器;它将通过映射接收数据的唯一方法是将源设置为通过自定义路由接收信息的事件中心。
是否可以通过物联网中心 -> 功能 -> 事件中心在数据资源管理器中提取数据?
编辑:
用于取消嵌套数据并将其转发到另一个事件中心的函数:
module.exports = async function (context, eventHubMessages) {
// receive message from IOT hub
eventHubMessages.forEach((message, index) => {
var devicename = message.deviceName;
// timestamp comes in two different texts, find and store correct one
var timestamp = (message.timestamp == null) ? message.timeStamp : message.timestamp;
//context.log("Message: " + JSON.stringify(message));
if (message.tags != null) {
message.tags.forEach((tag, index) => {
// for each tag, create new object
var name = tag.Name;
var value = tag.Value;
var newObject = {
"name":name,
"value": value,
"eventenqueuedutctime": timestamp,
"devicename": devicename
}
// output message object to 'splitmessage-dev' event hub
context.bindings.outputEventHubMessage = newObject
context.log("Sent object: " + JSON.stringify(newObject));
})
}
});
};
我可以确认其他事件中心正在接收此数据(使用另一个打印传入消息的函数进行检查)。
映射如下所示:
'testTableMap' '[{"column":"name", "path":"$.name"},
{"column":"value", "path":"$.value"},
{"column":"eventenqueuedutctime", "path":"$.eventenqueuedutctime"},
{"column":"devicename", "path":"$.devicename"}]'
应该可以使用您提供的设置摄取数据。
由于数据未被摄取,您可能应该尝试诊断卡在何处。
我将提供一些有助于调试的一般准则。
数据未到达配置为 ADX 数据源的 EventHub
您可以检查 EventHub 监控并验证事件是否在流动。 此外,我建议从 EventHub 读取数据,以确保它看起来像您期望的那样。 (好像你已经这样做了)
这里的情况似乎并非如此,因为您已经阐明您确实看到了流入 EventHub 的事件,并且您可以通过另一个函数成功读取它们。
Table / 映射配置不正确
尝试从配置的 EventHub 获取数据 manually
// create table
// I am assuming strings because other types can cause format errors,
// so I would try strings before other specific types (dynamic, datetime)
.create table IngestionTest (name: string, value:string, eventenqueuedutctime:string, devicename:string)
// add mapping
.create table IngestionTest ingestion json mapping 'testTableMap' '[{"column":"name", "path":"$.name"}, {"column":"value", "path":"$.value"}, {"column":"eventenqueuedutctime", "path":"$.eventenqueuedutctime"},{"column":"devicename", "path":"$.devicename"}]'
// ingest data manually - replace with you actual data
.ingest inline into table IngestionTest with (jsonMappingReference='testTableMap') <| '{ "name" : "test", "value": { "some":"nested", "value": true}, "eventenqueuedutctime" : "2016-01-14", "devicename": "surface" }'
如果上述方法不起作用,您可以通过 listing ingestion errors
尝试了解原因.show ingestion failures
如果以上方法有效,您可以尝试使用其他数据类型。
数据源监控
您可以通过 Azure 门户检查的另一件事是 ADX 集群的指标。
尝试在 Azure 门户中转到您的集群,在 Metrics
选项卡中,您可以选择两个可帮助您进行故障排除的指标:
Events Processed
- 让您了解 ADX 设法从 EventHub 读取了多少事件。这基本上让您知道数据源配置正确。如果您看不到事件,我建议您设置一个新的来源。
Ingestion Result
- 为您提供摄取状态(成功/失败)的计数,这也有助于诊断失败。