【发布时间】:2018-05-18 17:14:57
【问题描述】:
我在 kafka 上接收 protobuf 消息,消费者被配置为使用
反序列化事件value.deserializer = org.apache.kafka.common.serialization.StringDeserializer
如果我通过传递反序列化事件字符串的字节数组来使用com.google.protobuf.Parser 的parseFrom(byte[] data) 方法,该方法会抛出以下异常:
com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either than the input has been truncated or that an embedded message misreported its own length.
如果我改为使用
反序列化 kafka 事件value.deserializer = org.apache.kafka.common.serialization.ByteArrayDeserializer
并直接将接收到的字节数组传递给parseFrom,protobuf被正确解析,没有任何异常。
为什么第二种方法有效,而第一种方法无效?
【问题讨论】:
标签: java apache-kafka protocol-buffers