这是我的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函数代码中:
Source 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'
}
}
Destination EventHub事件:
{
body: { foo: 'transformedBar' },
properties: undefined,
offset: '34',
sequenceNumber: 456,
enqueuedTimeUtc: 2020-02-21T11:30:33.256Z,
partitionKey: undefined,
systemProperties: undefined
}
注意:我知道我可以“欺骗”并将deviceId附加到新事件的正文中,但是我需要在systemProperties
中彻底分隔此值,以便进一步处理该行。
context.bindings.eventHubDest = transformedMessageBody
)仅设置发送出去的消息的消息正文。这是一条全新的消息,而不仅仅是转发传入的消息。因此,任何元数据也会丢失。[读取this听起来像您在使用Java脚本时无法绑定到EventData
-因为you can when using C#.绑定到EventData使得您还可以设置元数据,而绑定到主体字符串则没有。
因此,我想如果需要的话,您需要使用C#(Java可能也可以使用)。或使用完全不同的工具,例如Azure流分析。