Kafka JsonDeserializer fails. What to do?

柔情痞子 提交于 2019-12-25 01:09:02

问题


I just want to know what is the best approach to handle json deserialisation errors while consuming data.

Lets say, my producer added below Json to topic:

{ "name":"John", "age":30 }

Later on producer changed the format of Json and now it started to add below message:

{ "surname":"Smith", "Country":"USA", "car":null }

On the other side I have Consumer which has Pojo with the fields name and age. Obviously my consumer(JsonDeserializer) is going to fail while deserialising second message.

Here is the question, how should I handle those kind of schema changes on the code side ? PreConditions:

  • I don't want to just log error or send those undeserilised messages to other topic.

  • I don't want to use Avro.

  • Only JsonDeserializer is allowed

Maybe the main question should be "if it is possible to save schemas of my Json messages to topic so that later if the format of message changes I would know how to deserialise them"

来源:https://stackoverflow.com/questions/57191872/kafka-jsondeserializer-fails-what-to-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!