简体   繁体   English

如何解决Kafka Avro反序列化问题

[英]How to solve Kafka Avro deserializing problem

we have a very strange behavior with an application which used kafka avro consumer and producer. 我们使用kafka avro消费者和生产者的应用程序有一个非常奇怪的行为。

We have a server where a confluent installation is running. 我们有一台运行融合安装的服务器。 All is configured manually so no confluent cli is used. 全部都是手动配置的,因此不会使用融合的cli。

On a second server there is an application running which uses this confluent installation to receive requests via Kafka topic. 在第二台服务器上,正在运行一个应用程序,该应用程序使用此融合安装来通过Kafka主题接收请求。 This request is translated into a database query and it sends back a reply topic with specific data. 该请求被转换为数据库查询,并发送回带有特定数据的回复主题。

On a third server there is another application there is the application which sends this requests to the application on server number 2 and receives the reply topics. 在第三台服务器上,存在另一个应用程序,该应用程序将该请求发送到2号服务器上的应用程序,并接收回复主题。

So to sum up: Server 1 (Confluent installation) Server 2 (Request Consumer and Reply Producer Application) Server 3 (Request Sender and Reply Consumer Application) 总结一下:服务器1(融合安装)服务器2(请求使用者和答复生产者应用程序)服务器3(请求发送者和答复消费者应用程序)

I developed a kafka API for us that all are using the consumer and producers with confluent avro serializer and deserializer. 我为我们开发了一个kafka API,所有人都在使用消费者和生产者以及融合的avro序列化器和解串器。 When i'm now producing a request topic from my app on Server 3 my app on Server 2 receives the request, translate it into a database query and sends back a reply topic which is different from the request topic. 当我现在从服务器3上的应用程序生成请求主题时,服务器2上的应用程序接收到请求,将其转换为数据库查询,然后发回与请求主题不同的回复主题。 Now my app on Server 3 should receive the test-reply-topic and deserialize it. 现在,我在服务器3上的应用程序应该收到test-reply-topic并反序列化它。

My test-reply-topic contains a "union{null, bytes} file" field. 我的test-reply-topic包含一个“ union {null,bytes}文件”字段。 So the field is optional, the default value is null and then schema is registered in the registry. 因此,该字段是可选的,默认值为null,然后在注册表中注册架构。 Now if the file value is null it's giving me an error: 现在,如果文件值为null,则会给我一个错误:

Error deserializing key/value for partition test-reply-topic-0 at offset 0. If needed, please seek past the record to continue consumption. 将偏移量为0的分区test-reply-topic-0的键/值反序列化时出错。如果需要,请查找记录以继续使用。 Cause: Error deserializing Avro message for id 6 Detailed: Found null, expecting bytes 原因:错误反序列化ID为6的Avro消息详细:发现为空,期望字节

If it is containing bytes it is working. 如果它包含字节,则它正在工作。

The strange thing is, that if I try the same from the local computer it is working with file=null and file=some bytes. 奇怪的是,如果我在本地计算机上尝试相同的操作,那么它将使用file = null和file = some字节。 So I'm using the same kafka broker, the same API and the same values in the producers and consumers. 所以我在生产者和消费者中使用相同的kafka代理,相同的API和相同的值。 It is requesting the same schema id from the registry on server and local computer. 它正在从服务器和本地计算机上的注册表中请求相同的架构ID。

Maybe somebody has some hints what the problem could be, I searching since days for this problem and don't find a solution. 也许有人暗示了这个问题可能是什么,我几天以来一直在寻找这个问题,却没有找到解决方案。

Many thanks in advance! 提前谢谢了!

Sorry for my late reply. 抱歉这么晚才回复。 So it turned out, that the application which had the deserialization problems, used old generated java classes. 结果发现,存在反序列化问题的应用程序使用了旧的生成的Java类。 So it used the old schemas, where there was no union type before. 因此,它使用了以前没有联合类型的旧模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM