【Azure Event Hub】Event Hub的Process Data页面无法通过JSON格式预览数据

发布时间 2023-07-24 15:20:32作者: 路边两盏灯

问题描述

在Event Hub的门户页面中,可以通过Process Data页面查看Event Hub中的数据,但是当使用JSON格式预览时(View in JSON),却出现错误。

消息一: No data was found for preview from 'test01'. Make sure the input has recently received data and the correct format of those events has been selected. [SessionID: 6b15d63464bf41f9b6e6c758f58a26ef 

消息二:Source '<unknown_location>' had 1 occurrences of kind 'InputDeserializerError.InvalidData' between processing times '2023-07-24T06:24:42.5057556Z' and '2023-07-24T06:24:42.5057556Z'. Could not deserialize the input event(s) from resource 'Partition: [0], Offset: [0], SequenceNumber: [0]' as Json. Some possible reasons: 1) Malformed events 2) Input source configured with incorrect serialization format

 

只是,在Event Hub中是存有数据的。如下图左边的Incoming Message中,有98条数据,但是在右边的Query页面中,却无法正确显示。

 

问题解答

在错误消息二中,出现了“ Input source configured with incorrect serialization format ”指明了数据解析为JSON过程中出现了不正确的序列化格式。这里就很明确的说明了无数据显示的原因是数据格式错误引起。 为了进一步调查这个问题,就需要通过其他方式获取出消息的内容,然后检查为什么它不是一个正确的JSON格式。

方式一:在Process Data页面中,选择 View by CSV - comma(,) 可以看见内容,但是发现格式很不一致,无法准确判断。

方式二:为了准确的获取到Event Hub中的数据,可以使用Azure Event Hub官方推荐的一个工具 Service Bus Explorer(下载地址:https://sourceforge.net/projects/service-bus-explorer.mirror/)来获取Event Hub中的数据。

操作动画演示:

在上图的工具中,直接查看到JSON的格式中,存在两个 Test/test, 虽然它们的首字母分别为大小写。

但是从测试的结果证明: Event Hub Process Data页面不识别大小写。所以在进行格式转换的时候抛出了 “InputDeserializerError.InvalidData : Input source configured with incorrect serialization format ”

 

最后确认

由于Event Hub的Process Data页面使用的是Azure中另一个服务ASA(流分析)来处理数据,在处理时识别不了有大小写不敏感的JSON字符串。由于ASA是大小写不敏感的流处理工具,所以在转换JSON时会忽略大小写,如果有相同的字段会解析失败。

所以,如果要查看数据,可以修改发送到Event Hub中的数据内容,或者通过Service Bus Explorer工具,及其他使用SDK自行编写的消费端代码。

 

参考资料

Service  Bus Explorer : https://sourceforge.net/projects/service-bus-explorer.mirror/

Use Service Bus Explorer to run data operations on Service Bus : https://learn.microsoft.com/en-us/azure/service-bus-messaging/explorer