1
votes

I'm using EventHubTrigger and EventData to receive IotHub message and I want to get "user-Id" in EventData.SystemProperties. Follow https://docs.microsoft.com/bs-cyrl-ba/azure/iot-hub/iot-hub-devguide-messages-construct I set Message.UserId by Microsoft.Azure.Devices.Client, but I still can not receive it in EvenData.SystemProperties

Thanks for your help

1
Did you use the code: Message msg = new Message { UserId = "FooUser" }? Which language did you use?duy

1 Answers

0
votes

The following screen snippets show an example of the user-id property on the telemetry data.

  1. The virtual device (represented by my Azure IoT Hub Tester) is publishing a telemetry data with systemproperty $.uid=ABCD1234

enter image description here

  1. The telemetry data are receiving by azure function:

    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)}");
    }
    
  2. The azure function log:

enter image description here

Note, that the value type of the user-id systemproperty is

ArraySegment<byte>