Hi Team, I am trying to consume data from kafka to...
# troubleshooting
a
Hi Team, I am trying to consume data from kafka topic which has proto data. My proto has nested fields and I getting serialisation error when trying to consume from the kafka topic. Please let me know how I can fix this error
Copy code
Caused by: com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException
Serialization trace:
ids_ (com.eventregistry.Ids)
res_ (com.eventregistry.Pojo)
Flink Version: v1.17.2
n
I doubt this is in any way Flink related. Can you reproduce this in a test?
a
What do you mean in a test? Do you need a dummy project with proto and kafka consumer code?
n
No not a dummy project, unit tests for your code. Full integration tests should also be here. There's something wrong with your deserializer. Mine isn't perfect but it looks like this:
Copy code
import org.apache.flink.api.common.serialization.DeserializationSchema
import org.apache.flink.api.common.typeinfo.TypeInformation
import org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema
import org.apache.flink.util.Collector
import org.apache.kafka.clients.consumer.ConsumerRecord

class KafkaRecordDeserializer : KafkaRecordDeserializationSchema<KafkaRecord> {
    override fun open(context: DeserializationSchema.InitializationContext) {
        super.open(context)
    }

    override fun getProducedType(): TypeInformation<KafkaRecord> {
        return TypeInformation.of(KafkaRecord::class.java)
    }

    override fun deserialize(
        record: ConsumerRecord<ByteArray, ByteArray>,
        out: Collector<KafkaRecord>,
    ) {
        out.collect(
            KafkaRecord(
                payload = KafkaRecord.Payload(value = record.value()),
                headers = record.headers(),
            ),
        )
    }
}
πŸ‘€ 1
this is kotlin btw
a
I think this is causing the issue
TypeInformation.of(new TypeHint<>() {})
I am not sure how to give type information of
Payload<T>
Copy code
public class Payload<T extends GeneratedMessageV3> {
    Long timestamp;
    private T payload;

    public Payload(T payload, Header headerInfo) {
        this.payload = payload;
        this.timestamp = headerInfo.getTimestamp().getSeconds();
    }

    public static <T extends GeneratedMessageV3> Payload<T> fromProto(
            JumboEvent originalProto,
            Class<T> payloadType
    ) throws InvalidProtocolBufferException {
        // Extract header information
        Header headerInfo = originalProto.getHeader();

        // Unpack the Any payload
        Any payload = originalProto.getPayload();
        T specificPayload = payload.unpack(payloadType);
        return new Payload<>(specificPayload, headerInfo);
    }
}
j
@Ayush Chauhan can you try adding these lines in your code:
Copy code
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().registerTypeWithKryoSerializer(<YOUR_CLASS_HERE>.class, ProtobufSerializer.class);
a
@Jasmin Redzepovic yes it works Is there any flink native support for this? Since this repo was last updated 3 years ago https://github.com/twitter/chill/blob/v0.10.0/chill-protobuf/src/main/java/com/twitter/chill/protobuf/ProtobufSerializer.java