Reputation: 45
Looks like KakfkaTemplate can be configured using generics to indicate the Key and a Value. Is the type of key specific for a use case? e.g. some identifying information like personId, patientId, the value would present some sort of a pojo (DTO, probably not an entire JPA entity)
This leads to a question, should we configure multiple KafkaTemplates depending on use case (for each topic) ?
Upvotes: 1
Views: 1431
Reputation: 121462
The KakfkaTemplate
is generic for coding convenience.
But if your different topics deals with different data types, you really should consider to have a separate type-safe KakfkaTemplate
for that purpose.
Another note: the KakfkaTemplate
is fully based on the KafkaProducer
, which requires particular ProducerProperties
including key/value
serializers.
So, yes, for different data types you need separate KafkaProducer
s and, therefore, KakfkaTemplate
. Even if they look into the same Kafka Broker.
Upvotes: 3