SystemProperties not populated for Azure.Messaging.EventHubs.EventData?

255 Views Asked by At

We have recently upgraded our Service Fabric service that reads messages from Azure IoT Hub built-in Event Hub from the deprecated Microsoft.Azure.EventHubs SDK to Azure.Messaging.EventHubs SDK (following this migration guide).

We are running into an issue where the SystemProperties for the EventData class are not fully populated. Specifically, message-id, correlation-id, and user-id properties come in with no data, as seen here:

{"message-id":{},"user-id":{"Length":0,"IsEmpty":true},"correlation-id":{},"iothub-connection-device-id":"xxxxxxx","iothub-connection-auth-method":"{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}","iothub-connection-auth-generation-id":"xxxxxxxxxxxxxxxxx","iothub-enqueuedtime":"2023-07-13T22:00:53.501Z","iothub-message-source":"Telemetry","x-opt-sequence-number":4785508,"x-opt-offset":1005023123136,"x-opt-enqueued-time":"2023-07-13T22:00:53.652+00:00"}

We are using an EventProcessorClient with the AmqpTcp transport type.

Can anyone help us in determining why these system properties are not being populated? This worked previously with the deprecated SDK.

Any help is appreciated.

2

There are 2 best solutions below

0
Sampath On BEST ANSWER

According to this MSDOC the events that are received through the Event Hubs service have these characteristics filled. The events received from other sets empty.

 static async Task ReceiveMessagesFromEventHub()
    {
        await using var consumerClient = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, connectionString, eventHubName);
          await foreach (PartitionEvent partitionEvent in consumerClient.ReadEventsAsync())
        {
            EventData eventData = partitionEvent.Data;
            object messageId = eventData.Properties["message-id"];
            object correlationId = eventData.Properties["correlation-id"];
            object userId = eventData.Properties["user-id"];
            object Iotubconectiondevidid = eventData.Properties["iothub - connection - device - id"];
            object iothubconnectionauthmethod = eventData.Properties["iothub - connection - auth - method"];

Refer this for Missing IoT Hub System Properties and SO.

Event From Iot Hub:

enter image description here

Event from Event Hubs:

enter image description here

0
TheTurkishDeveloper On

Additionally for anyone who encounters this issue, I also discovered a related issue to my original problem in that we were using some custom properties (with EventData.Properties) that were also not being populated.

Turns out that the Properties Dictionary keys are case-sensitive, where before we upgraded to System.Messaging.EventHubs they were not. I know this because I had two sets of devices sending messages to Azure IoT Hub (one used all lower-case property keys and one that used case-sensitive property keys) and they both worked correctly prior to the upgrade.

Tweaking my code that retrieves these property values to retrieve by case-insensitive keys fixed the issue, along with the other accepted answer by @Sampath.