SystemProperties未填充到Azure.Messaging.EventHubs.EventData中?

huangapple go评论57阅读模式
英文:

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

问题

我们最近将从已弃用的Microsoft.Azure.EventHubs SDK迁移到Azure.Messaging.EventHubs SDK的Service Fabric服务进行了升级(遵循此迁移指南)。

我们遇到一个问题,即EventData类的SystemProperties未完全填充。具体来说,message-idcorrelation-iduser-id属性没有数据,如下所示:

{"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"}

我们正在使用带有AmqpTcp传输类型的EventProcessorClient

有人能帮助我们确定为什么这些系统属性没有填充吗?在使用已弃用的SDK时,这是有效的。

感谢任何帮助。

英文:

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.

答案1

得分: 1

根据此MSDOC,通过Event Hubs服务接收的事件具有以下填充的特性。从其他地方接收的事件则为空。

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"];
    }
}

参考此链接查看缺失的IoT Hub系统属性,以及Stack Overflow

来自IoT Hub的事件:

SystemProperties未填充到Azure.Messaging.EventHubs.EventData中?

来自Event Hubs的事件:

SystemProperties未填充到Azure.Messaging.EventHubs.EventData中?

英文:

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:

SystemProperties未填充到Azure.Messaging.EventHubs.EventData中?

Event from Event Hubs:

SystemProperties未填充到Azure.Messaging.EventHubs.EventData中?

答案2

得分: 0

此外,对于任何遇到此问题的人,我还发现了一个与我的原始问题相关的问题,即我们使用了一些自定义属性(使用EventData.Properties)也没有被填充。

原来,属性字典的键是区分大小写的,在我们升级到System.Messaging.EventHubs之前它们不是。我知道这一点,因为我有两组设备发送消息到Azure IoT Hub(一组使用全部小写属性键,另一组使用区分大小写的属性键),在升级之前它们都能正常工作。

通过调整检索这些属性值的代码,以按不区分大小写的键进行检索,问题得以解决,还有@Sampath提供的其他可接受的答案。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月14日 06:48:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683711.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定