org.apache.kafka.common.errors.SerializationException: Error deserializing... Caused by: org.apache.kafka.common.errors.SerializationException: Size of data received by IntegerDeserializer is not 4

原因,最近开发的kafka消息接收,突然报如下错:

org.apache.kafka.common.errors.SerializationException: Error deserializing... Caused by: org.apache.kafka.common.errors.SerializationException: Size of data received by IntegerDeserializer is not 4

原因如下,我的kafka序列化配置中配置的序列化类如下:

key.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer
value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
IntegerDeserializer源码如下:
public Integer deserialize(String topic, byte[] data) {
        if (data == null) {
            return null;
        } else if (data.length != 4) {
            throw new SerializationException("Size of data received by IntegerDeserializer is not 4");
        } else {
            int value = 0;
            byte[] arr$ = data;
            int len$ = data.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                byte b = arr$[i$];
                value <<= 8;
                value |= b & 255;
            }

            return value;
        }
    }

解决方法,将配置做如下修改:

key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
value.deserializer=org.apache.kafka.common.serialization.StringDeserializer

问题解决。

 
posted @ 2020-07-09 11:20  莫等、闲  阅读(4471)  评论(0编辑  收藏  举报