I am trying to follow the instructions here:
To set up a KafkaTemplate that can serialize and send some simple Java POJOs that I have. But I found the documentation vague and confusing, especially this part:
For this purpose Spring for Apache Kafka also provides JsonSerializer/JsonDeserializer implementations based on the Jackson JSON processor. When JsonSerializer is pretty simple and just lets to write any Java object as a JSON byte[]
...
Although Serializer/Deserializer API is pretty simple and flexible from the low-level Kafka Consumer and Producer perspective, it is not enough on the Messaging level, where KafkaTemplate and @KafkaListener are present.
...
The MessageConverter can be injected into KafkaTemplate instance directly and via AbstractKafkaListenerContainerFactory bean definition for the @KafkaListener.containerFactory() property
So my question is:
- What is the type of my KafkaTemplate? Is it
KafkaTemplate<String, Object>
? Or is itKafkaTemplate<String, String>
? - What is my
Serializer class? Is it
StringSerializer
, or is itJsonSerializer
? - Do
I use
kafkaTemplate.setMessageConverter(new StringJsonMessageConverter())
when creating my KafkaTemplate bean?
Apologies if these are stupid questions - I'm trying to understand the correct way of setting it up rather than "hacking it till it kinda works".