Azure functions “如何接收”;用户Id“;关于物联网中心信息

Azure functions “如何接收”;用户Id“;关于物联网中心信息,azure-functions,azure-iot-hub,Azure Functions,Azure Iot Hub,我正在使用EventHubTrigger和EventData接收IotHub消息,我想在EventData.SystemProperties中获取“用户Id”。跟随 我通过Microsoft.Azure.Devices.Client设置了Message.UserId,但仍然无法在EvenData.SystemProperties中接收它 感谢您的帮助以下屏幕片段显示了遥测数据的用户id属性示例 虚拟设备(由my表示)正在发布systemproperty$.uid=ABCD1234的遥测数据 a

我正在使用EventHubTrigger和EventData接收IotHub消息,我想在EventData.SystemProperties中获取“用户Id”。跟随 我通过Microsoft.Azure.Devices.Client设置了Message.UserId,但仍然无法在EvenData.SystemProperties中接收它


感谢您的帮助

以下屏幕片段显示了遥测数据的用户id属性示例

  • 虚拟设备(由my表示)正在发布systemproperty$.uid=ABCD1234的遥测数据
  • azure功能正在接收遥测数据:

    public static void Run2([IoTHubTrigger("messages/events", Connection = "AzureIoTHubConnectionString")]EventData message, ILogger log)
    {
        log.LogInformation($"\nBody:\n\t{Encoding.UTF8.GetString(message.Body.Array)}" +
                           $"\nSystemProperties:\n\t{string.Join("\n\t", message.SystemProperties.Select(i => $"{i.Key}={i.Value}"))}" +
                           $"\nProperties:\n\t{string.Join("\n\t", message.Properties.Select(i => $"{ i.Key}={ i.Value}"))}");          
    
        log.LogInformation($"user-id={System.Text.Encoding.UTF8.GetString(((ArraySegment<byte>)message.SystemProperties["user-id"]).Array)}");
    }
    
    publicstaticvoidrun2([IoTHubTrigger(“messages/events”,Connection=“AzureIoTHubConnectionString”)]事件数据消息,ILogger日志)
    {
    log.LogInformation($“\n正文:\n\t{Encoding.UTF8.GetString(message.Body.Array)}”+
    $“\n系统属性:\n\t{string.Join(“\n\t”,message.SystemProperties.Select(i=>$”{i.Key}={i.Value}”))}”+
    $“\n属性:\n\t{string.Join(“\n\t”,message.Properties.Select(i=>$”{i.Key}={i.Value}”))});
    log.LogInformation($”用户id={System.Text.Encoding.UTF8.GetString(((ArraySegment)message.SystemProperties[“user id”]).Array)}”);
    }
    
  • azure功能日志:

  • 请注意,用户id systemproperty的值类型为

    ArraySegment<byte>
    
    ArraySegment
    
    以下屏幕片段显示遥测数据的用户id属性示例

  • 虚拟设备(由my表示)正在发布systemproperty$.uid=ABCD1234的遥测数据
  • azure功能正在接收遥测数据:

    public static void Run2([IoTHubTrigger("messages/events", Connection = "AzureIoTHubConnectionString")]EventData message, ILogger log)
    {
        log.LogInformation($"\nBody:\n\t{Encoding.UTF8.GetString(message.Body.Array)}" +
                           $"\nSystemProperties:\n\t{string.Join("\n\t", message.SystemProperties.Select(i => $"{i.Key}={i.Value}"))}" +
                           $"\nProperties:\n\t{string.Join("\n\t", message.Properties.Select(i => $"{ i.Key}={ i.Value}"))}");          
    
        log.LogInformation($"user-id={System.Text.Encoding.UTF8.GetString(((ArraySegment<byte>)message.SystemProperties["user-id"]).Array)}");
    }
    
    publicstaticvoidrun2([IoTHubTrigger(“messages/events”,Connection=“AzureIoTHubConnectionString”)]事件数据消息,ILogger日志)
    {
    log.LogInformation($“\n正文:\n\t{Encoding.UTF8.GetString(message.Body.Array)}”+
    $“\n系统属性:\n\t{string.Join(“\n\t”,message.SystemProperties.Select(i=>$”{i.Key}={i.Value}”))}”+
    $“\n属性:\n\t{string.Join(“\n\t”,message.Properties.Select(i=>$”{i.Key}={i.Value}”))});
    log.LogInformation($”用户id={System.Text.Encoding.UTF8.GetString(((ArraySegment)message.SystemProperties[“user id”]).Array)}”);
    }
    
  • azure功能日志:

  • 请注意,用户id systemproperty的值类型为

    ArraySegment<byte>
    
    ArraySegment
    
    您是否使用了代码:Message msg=new Message{UserId=“FooUser”}?您使用了哪种语言?您是否使用了代码:Message msg=new Message{UserId=“FooUser”}?你用哪种语言?