【发布时间】:2020-02-22 02:28:17
【问题描述】:
这是我的 Azure 管道:
IoTHub → EventHub src → JavaScript 中的 Azure 函数 → EventHub dest
在 Azure 函数中,我需要对作为输入接收的事件主体应用一些转换,并将转换后的事件放入目标 EventHub。
通过context.bindingData.systemPropertiesArray,我可以检索iothub-connection-device-id 等基本元数据:
module.exports = async function (context, messageBodies) {
messageBodies.forEach((messageBody, index) => {
const transformedMessageBody = transform(messageBody)
const deviceId = context.bindingData.systemPropertiesArray[index]['iothub-connection-device-id']
context.log(deviceId)
// here I can only set the messageBody. What's the way to attach back the original systemProperties?
context.bindings.eventHubDest = transformedMessageBody
})
}
问题:systemProperties 在目标 EventHub 中丢失,因为我可以找到一种方法将它们重新设置在 Azure 函数代码中:
来源 EventHub 事件:
{
body: { foo: 'bar' },
properties: undefined,
offset: '143360',
sequenceNumber: 392,
enqueuedTimeUtc: 2020-02-21T11:30:32.294Z,
partitionKey: undefined,
systemProperties: {
'iothub-connection-device-id': 'qux',
'iothub-connection-auth-method': '{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}',
'iothub-connection-auth-generation-id': '637177867069071846',
'iothub-enqueuedtime': 1582284632134,
'iothub-message-source': 'Telemetry'
}
}
目标 EventHub 事件:
{
body: { foo: 'transformedBar' },
properties: undefined,
offset: '34',
sequenceNumber: 456,
enqueuedTimeUtc: 2020-02-21T11:30:33.256Z,
partitionKey: undefined,
systemProperties: undefined
}
注意:我知道我可以“作弊”并将 deviceId 附加到新事件的正文中,
但我需要在systemProperties 中将这个值完全分开,以便进一步处理。
【问题讨论】:
标签: azure-functions azure-iot-hub azure-eventhub