Does anyone have issues with JSON Serializer in Kafka?
Last updated on
I am trying to use the JSON deserializer for Kafka (with Spring) and keep having issues. Specifically it seems to throw the service into an infinite loop resulting in out of memory error...
Any help greatly appreciated.
Share your thoughts
Yes blazing..this is a common problem with using the JsonDeserializer class provided by Kafka.
Yes super annoying. I have to continuously manually reset offset to latest to get it to skip past the bad record and keep consuming. Not sustainable for sure. Any help is greatly appreciated on this.
The problem is this:
The JsonDeserializer class is based on the Jackson ObjectMapper. When Kafka tries to deserialize an incoming message to a topic, if there is an ObjectMapper related error then it will be thrown before the poll() method has a chance to return...
The solution is rather simple. You just configure your Spring Kafka to use the ErrorHandlingDeserializer. Here is an example of working configuration...
You have to define a class for the ErrorHandlingDeserializer to delegate to. If something goes wrong, an exception will be handled (avoiding the infinite loop) and the message won't be sent to the listener.