Azure functions 如何在Azure函数中设置EventHub上的systemProperties out绑定

Azure functions 如何在Azure函数中设置EventHub上的systemProperties out绑定,azure-functions,azure-iot-hub,azure-eventhub,Azure Functions,Azure Iot Hub,Azure Eventhub,以下是我的Azure管道: IoTHub→ 事件中心→ JavaScript中的Azure函数→ 事件中心目的地 在Azure函数中,我需要对作为输入接收的事件体应用一些转换,并将转换后的事件放在目标EventHub中 通过context.bindingData.systemPropertiesArray,我能够检索基本元数据,如IoHub连接设备id: module.exports=异步函数(上下文、消息体){ messageBody.forEach((messageBody,index)=>

以下是我的Azure管道:

IoTHub→ 事件中心→ JavaScript中的Azure函数→ 事件中心目的地

在Azure函数中,我需要对作为输入接收的事件体应用一些转换,并将转换后的事件放在目标EventHub中

通过
context.bindingData.systemPropertiesArray
,我能够检索基本元数据,如
IoHub连接设备id

module.exports=异步函数(上下文、消息体){
messageBody.forEach((messageBody,index)=>{
const transformedMessageBody=转换(messageBody)
const deviceId=context.bindingData.systemPropertiesArray[index]['iothub-connection-device-id']
context.log(设备ID)
//这里我只能设置messageBody。如何附加回原始的systemProperties?
context.bindings.eventHubDest=transformedMessageBody
})
}
问题:目标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'
      }
    }

   {
      body: { foo: 'transformedBar' },
      properties: undefined,
      offset: '34',
      sequenceNumber: 456,
      enqueuedTimeUtc: 2020-02-21T11:30:33.256Z,
      partitionKey: undefined,
      systemProperties: undefined
   }

目标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'
      }
    }

   {
      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
)仅设置发送的消息的消息体。这是一条全新的消息,而不仅仅是转发传入的消息。因此,任何元数据也会丢失

阅读它听起来像是在使用Javascript时无法绑定到
EventData
,因为绑定到EventData还可以设置元数据,而绑定到body字符串则不能


所以我想如果你需要,你需要使用C(Java也可以)。或者使用完全不同的东西,如Azure Stream Analytics。

无法在事件中心发布服务器上设置SystemProperties,因为它仅用于服务。我不确定在JS触发器中是如何实现的,但是您应该使用eventData.properties包。

我尝试了一个C#Azure函数<代码>系统属性即使不接触输入事件也会丢失。正如Serkant Karaca所说,
SystemProperties
必须从输入事件复制到输出绑定
Properties
。这就是为什么我写了“这是一条全新的消息,而不仅仅是转发传入的消息”。但是Serkant是正确的,您只能设置“应用程序/用户定义属性”,而不能设置系统属性