How to handle SerializationException after deserialization

前端 未结 1 1879
囚心锁ツ
囚心锁ツ 2021-02-20 18:59

I am using Avro and Schema registry with my Spring Kafka setup.

I would like to somehow handle the SerializationException, which might be thrown during dese

相关标签:
1条回答
  • 2021-02-20 19:47

    There is nothing Spring can do; the deserialization occurs before the consumer gets any data. You need to enhance the deserializer.

    I would however like to be able to throw an exception instead of returning null.

    That won't help anything since Kafka won't know how to deal with the exception. Again; this all happens before the data is available so returning null (or some other special value) is the best technique.

    EDIT

    In 2.2, we added an error handling deserializer which delegates to the actual deserializer and returns null, with the exception in a header; the listener container then passes this directly to the error handler instead of the listener.

    0 讨论(0)
提交回复
热议问题