3

I would like to know if I need a custom serializer for producing JSON messages into the kafka queue. I don't necessarily work with objects while producing, but the messages that I get will be in the JSON format which I need to push into the kafka queue. The consumers will be responsible for parsing the JSON to the object they need.

Now, I would like to know whether I need a custom serializer to produce a JSON formatted message into the queue because after all JSON message is going to be a simple string.

JavaTechnical
  • 8,846
  • 8
  • 61
  • 97

1 Answers1

2

I think yes you need to implement your own custom serializer as the default one. By default the String serializer class is shipped with Kafka. You need to impement the Encoder<T> class and then override the toBytes(..) method.

Here is a nice post that talks about implementing a similar custom serializer.

Community
  • 1
  • 1
user2720864
  • 8,015
  • 5
  • 48
  • 60
  • I don't get this - why would one need a custom serializer for producing to kafka ? It might be needed on the consumer side to encapsulate the logic for converting JSON message from kafka to whatever domain object the application needs. Am I missing something ? – Abhishek May 18 '17 at 08:09