相关疑难解决方法(0)

Azure IoT Hub,EventHub和Functions

我有一个IoTHub,其路由指向触发函数的EventHub.

我在从事件对象获取DeviceId和其他IoT Hub属性时遇到问题,而没有将这些属性显式添加到有效负载.

如果我将输入类型设置为string(或自定义类型):

public static void Run(string iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {iotMessage}");
}
Run Code Online (Sandbox Code Playgroud)

我只获得有效负载而没有任何其他IoT Hub属性,如DeviceId,CorrelationIdMessageId.

我尝试将类型设置为EventData:

public static void Run(EventData iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {JsonConvert.SerializeObject(iotMessage)}");
}
Run Code Online (Sandbox Code Playgroud)

现在我可以通过两个getter访问IoT Hub属性:Properties和SystemProperties.例如,我可以像这样访问DeviceId iotMessage.SystemProperties["iothub-connection-device-id"].但它不会暴露有效载荷.

那么如何访问IoT Hub属性和有效负载?

azure azure-eventhub azure-iot-hub azure-functions

7
推荐指数
1
解决办法
2110
查看次数