Search code examples
javaapache-kafkaprotocol-buffersspring-kafka

Can we directly use the protobuf in spring-kafka?


I want to create the a spring boot application with Kafka where producer and consumer both will use the protobuf only.

I tried with confluent deserializer but while trying that I'm getting so many parsing errors.


Solution

  • Yes, you should be able to use protobuf-java to create a byte[] that can be sent with ByteArraySerializer or get Message from byte array returned from ByteArrayDeserializer. Spring Boot is not necessary.

    Otherwise, you need to write your own Serializer and Deserializer implementations for using Protobuf Message class, or POJOs.

    You'll have the same "parser issues", regardless of what framework is used, if your protobuf schema definition is invalid, as Confluent simply wraps that same library.