英文:
Custom Kafka Deserializer ignores null messages
问题
我正在使用Kotlin Spring Boot,并且我有一个自定义的Kafka反序列化器。问题是,自定义的Deserializer
完全忽略了具有空值的消息。是否有一种方法让空消息通过deserialize
方法?
我正在在application.yaml上设置自定义Deserialiserlizer
spring:
kafka:
consumer:
value-deserializer: mypackage.CustomDeserializer
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
而CustomDeserializer如下
class CustomDeserializer : Deserializer<Result<MyData?>> {
private val log = logger()
override fun deserialize(topic: String?, data: ByteArray?): Result<MyData?> {
//反序列化逻辑
}
}
英文:
I'm using Kotlin Spring Boot and I have a custom Kafka Deserialiser. The issue is that the custom Deserializer
complete ignores messages that have null values. Is there a way for null messages to go through the deserialize
method?
I'm setting the custom Deserialiserlizer on application.yaml
spring:
kafka:
consumer:
value-deserializer: mypackage.CustomDeserializer
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
And the CustomDeserializer is like
class CustomDeserializer : Deserializer<Result<MyData?>> {
private val log = logger()
override fun deserialize(topic: String?, data: ByteArray?): Result< MyData?> {
//deserialisation logic
}
}
答案1
得分: 1
这不是预期的行为。查看 Kafka 源代码 可接受空字节数组。
也许你确实需要在Java中实现这个类,因为ByteArray?
和byte[]
可能不会编译成相同的值?
另外,正如评论中提到的,你可以使用基于Avro、Protobuf或JSON数据的现有反序列化器。
英文:
This is not expected behavior. See Kafka Source Code that does accept null byte arrays.
Perhaps you do need to implement the class in Java since ByteArray?
and byte[]
may not compile to the same value?
Alternatively, as mentioned in the comments, you could use existing Deserializers that are based on Avro, Protobuf, or JSON data.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论